I want to put ButtonTool in the large round button in the upper-left corner of the Ribbon (actually this is the RootToolsCollection ). When I try to do it it throws exception the there is no UI Adapter to handle RootToolsCollection. How can I do this to work?
Thanks, I did it. The problem was that I didn't return reference of the ButtonTool when I registered it.
ButtonTool instance is not null, but ButtonTool.InstanceProps are null
That's weird.
I have made the same mistake you did the first time I tried to add a tool to the ribbon. After that I have found a knowledge base article on infragistics.com that shown how a tool should be added to the ribbon in a CAB application. I've got this solution that works in a deployed application:
// create the tab and add it to the tabs collection _pacientTab = new RibbonTab("TabPacient", "Pacient"); WorkItem.UIExtensionSites[UIExtensionSiteNames.RibbonTabs].Add(_pacientTab); WorkItem.UIExtensionSites.RegisterSite(Constants.UIExtensionSiteNames.PacientTabGroups, _pacientTab.Groups); // create the group and add it to the groups collection in pacient tab RibbonGroup pacientGroup = new RibbonGroup("GroupPacient", "Actions"); WorkItem.UIExtensionSites[Constants.UIExtensionSiteNames.PacientTabGroups].Add(pacientGroup); WorkItem.UIExtensionSites.RegisterSite(Constants.UIExtensionSiteNames.PacientTabActionsGroupTools, pacientGroup.Tools); ButtonTool addPacient = new ButtonTool("AddPacient"); addPacient.SharedProps.Caption = "Add..."; addPacient.SharedProps.ToolTipText = "Add a new pacient"; addPacient.SharedProps.AppearancesLarge.Appearance.Image = Resources.pacient_adauga; addPacient = WorkItem.UIExtensionSites[Constants.UIExtensionSiteNames.PacientTabActionsGroupTools].Add(addPacient); addPacient.InstanceProps.PreferredSizeOnRibbon = RibbonToolSize.Large; addPacient.InstanceProps.IsFirstInGroup = true; WorkItem.Commands[CommandNames.AddPacient].AddInvoker(addPacient, "ToolClick");
In your case, the returned reference after adding the tool to the UIExtensionSite is null?
If I Did it using your way it throws Null Reference Exception
When you add a tool to the ribbon, a clone is made and added. The SharedProps are cloned, but the InstanceProps are not. You should get a reference to the added tool and then set the instance props.
So instead of you code:
smartgen said: RibbonGroup actionTabGroup = new RibbonGroup("actionTabGroup", "Group 1 in Tab 2"); RootWorkItem.UIExtensionSites["ribbonTab1Groups"].Add(actionTabGroup); ; RootWorkItem.UIExtensionSites.RegisterSite("actionTabGroupTools", actionTabGroup.Tools); // Create a ButtonTool and add it to ribbonTab2Group1 Infragistics.Win.Appearance addAppearance = new Infragistics.Win.Appearance(); addAppearance.Image = Properties.Resources.add; addAppearance.ImageVAlign = Infragistics.Win.VAlign.Top; ButtonTool addButton = new ButtonTool("ribbonTab2Group1Button2"); addButton.SharedProps.DisplayStyle = ImageAndText; addButton.SharedProps.Caption = "Add"; addButton.InstanceProps.MinimumSizeOnRibbon = Infragistics.Win.UltraWinToolbars.RibbonToolSize.Large; addButton.InstanceProps.PreferredSizeOnRibbon = RibbonToolSize.Large; addButton.SharedProps.AppearancesLarge.Appearance = addAppearance; RootWorkItem.UIExtensionSites["actionTabGroupTools"].Add(addButton);
RibbonGroup actionTabGroup = new RibbonGroup("actionTabGroup", "Group 1 in Tab 2"); RootWorkItem.UIExtensionSites["ribbonTab1Groups"].Add(actionTabGroup); ; RootWorkItem.UIExtensionSites.RegisterSite("actionTabGroupTools", actionTabGroup.Tools); // Create a ButtonTool and add it to ribbonTab2Group1 Infragistics.Win.Appearance addAppearance = new Infragistics.Win.Appearance(); addAppearance.Image = Properties.Resources.add; addAppearance.ImageVAlign = Infragistics.Win.VAlign.Top; ButtonTool addButton = new ButtonTool("ribbonTab2Group1Button2"); addButton.SharedProps.DisplayStyle = ImageAndText; addButton.SharedProps.Caption = "Add"; addButton.InstanceProps.MinimumSizeOnRibbon = Infragistics.Win.UltraWinToolbars.RibbonToolSize.Large; addButton.InstanceProps.PreferredSizeOnRibbon = RibbonToolSize.Large; addButton.SharedProps.AppearancesLarge.Appearance = addAppearance; RootWorkItem.UIExtensionSites["actionTabGroupTools"].Add(addButton);
, you should write:
RibbonGroup actionTabGroup = new RibbonGroup("actionTabGroup", "Group 1 in Tab 2"); RootWorkItem.UIExtensionSites["ribbonTab1Groups"].Add(actionTabGroup); ; RootWorkItem.UIExtensionSites.RegisterSite("actionTabGroupTools", actionTabGroup.Tools); // Create a ButtonTool and add it to ribbonTab2Group1 Infragistics.Win.Appearance addAppearance = new Infragistics.Win.Appearance(); addAppearance.Image = Properties.Resources.add; addAppearance.ImageVAlign = Infragistics.Win.VAlign.Top; ButtonTool addButton = new ButtonTool("ribbonTab2Group1Button2"); addButton.SharedProps.DisplayStyle = ImageAndText; addButton.SharedProps.Caption = "Add"; addButton.SharedProps.AppearancesLarge.Appearance = addAppearance; // add the button to the UIExtension Site addButton = RootWorkItem.UIExtensionSites["actionTabGroupTools"].Add(addButton); // set its instance props addButton.InstanceProps.MinimumSizeOnRibbon = Infragistics.Win.UltraWinToolbars.RibbonToolSize.Large; addButton.InstanceProps.PreferredSizeOnRibbon = RibbonToolSize.Large;
HTH,Emanuel