I am trying to create a Ribbon using only csharp code. I have been unable to get a RibbonButton to show up on the Ribbon. I have gotten a Tab and a Group to appear. I have tried setting every label and image property on the associated
RibbonCommand, but this does not help either. Does anyone have any clues as to what I am doing wrong?
public partial class Window1 : RibbonWindow
Ribbon r = new Ribbon();
r.Tabs.Label = "Foo";
RibbonGroup rg = new RibbonGroup();
RibbonCommand rc = new RibbonCommand("FooBarCmd", GetType());
rc.LabelTitle = "Foo Bar Cmd";
rg.Command = rc;
rg.GroupSizeDefinitions = new System.Collections.ObjectModel.Collection<RibbonGroupSizeDefinition>();
RibbonGroupSizeDefinition rgsd = new RibbonGroupSizeDefinition();
RibbonControlSizeDefinition rcsd = new RibbonControlSizeDefinition();
rcsd.IsImageVisible = false;
rcsd.IsLabelVisible = true;
rg.ItemsPanel = new RibbonGroupPanel();
RibbonButton rb = new RibbonButton(); //THIS BUTTON NEVER APPEARS
RibbonCommand rc2 = new RibbonCommand("my first cmd", GetType());
rb.Command = rc2;
StackPanel sp = new StackPanel();
Content = sp;
Add the following line to your RibbonCommand:
rc2.LabelTitle = "Test";
That will cause the button to appear. You will need to add additional attributes to your command to stylize the control. The below Xaml code is taken from the AppCommands.xaml file from one of the code examples. Simply add in the appropriate attributes to your
RibbonCommand as necessary to make it visible.
ToolTipDescription="Copy text element to the clipboard."
Thanks that works for that example. Unfortunately in my real program I was already doing that, and it is still not showing. At least now I have something that works to work off of.