Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
adding tools at runtime to ribbon.
posted
I am able to create the ribbon, and the group and set that all up properly, I am even able to add the buttons dynamically at runtime. The issue I am currently having is setting the image on the button. When the ribbon finally renders, I can see the buttons and you can tell that the image is there, because the button is moved slightly to the left to compensate for the icon, but the icon is not displayed. I have a factory class which based on the command object passed in creates the appropriate tool. for example I have a RibbonButtonTool class which returns a ToolBase which is a ButtonTool. Here is my method that creates the tool, in this case a button tool. public ToolBase Create(ICommand command) { ButtonTool button = null; try { button = new ButtonTool(command.Name) { Tag = command }; button.SharedProps.Caption = command.Text; if (command.Icon != null) { button.SharedProps.AppearancesSmall.Appearance.Image = command.Icon; button.SharedProps.DisplayStyle = ToolDisplayStyle.ImageAndText; } button.SharedProps.Visible = command.Visible; button.SharedProps.Enabled = command.Enabled; button.SharedProps.ToolTipText = (string.IsNullOrEmpty(command.ToolTip)) ? command.Text : command.ToolTip; button.SharedProps.Shortcut = command.KeyBoardShortcut; button.ToolClick += (s, e) => command.Execute(); } catch (Exception ex) { TraceTopics.Ribbon.exception(ex); } return button; } so now I would have a reference to a tool: var tool = ButtonTool.Create(ICommand command); manager.Tools.Add(tool); //manager is a reference to the UltraToolbarsManager //I then add the tool to the group that was created by the manager ribbonGroup.Tools.AddTool(command.Name); This all works fine, I can see the buttons on the tool bar and all their text and all the click events work, what I do not see are the icons I am setting the image too. I also tested the icons using the generic designer, so the icons do work with the tool bar ribbon. I also tried the following: var instanceTool = ribbonGroup.Tools.AddTool(command.Name); instanceTool.InstanceProps.PreferredSizeOnRibbon = RibbonToolSize.Normal; instanceTool.InstanceProps.DisplayStyle = tool.SharedProps.DisplayStyle; instanceTool.InstanceProps.AppearancesSmall.Appearance.Image = tool.SharedProps.AppearancesSmall.Appearance.Image; I read about getting a reference to the instance object, but the image still will not show. Any help would be greatly appreciated, and I apologize if I did not provide enough info at first. Thanks CD instanceTool.InstanceProps.Visible = DefaultableBoolean.True;
Parents
No Data
Reply
  • 44743
    Verified Answer
    posted

    If your command's icon is an instance of the .Net type System.Drawing.Icon, this is correct behavior. The Infragistics controls do not support using Icons, only Image types. Call ToBitmap on your Icon and pass in the returned value to the Appearance's Image.

Children