Creating Ribbon from code only without XAML

Nov 14, 2008 at 3:47 AM
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
        public Window1()
            Ribbon r = new Ribbon();
            r.Tabs.Add(new RibbonTab());
            r.Tabs[0].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;
Nov 14, 2008 at 9:01 PM
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.

<r:RibbonCommand x: Key ="CopyCommand"



ToolTipDescription="Copy text element to the clipboard."


LargeImageSource="images/Copy.png" />"

Nov 15, 2008 at 7:38 PM
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.