Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

A Demonstration for WPF Ribbon Control Library

0.00/5 (No votes)
25 Apr 2008 1  
A demonstration application for showing the use of the WPF Ribbon Control as presented elsewhere

Current Version 1.0.0.10

Introduction

This article serves as a practical demonstration of the Ribbon Control and associated Office UI Guideline components as presented in the article shown here (a WPF C# Ribbon Control Library). Read this article before using this code.

This article does not present an overview or otherwise of how to use the library but presents only a specific demonstration application and points of interest when using the library; for fuller information on the library, please see the main article linked above.

The article presents a demonstration application using version 1.0.0.10 of the library.

Background (optional)

See WPF C# Ribbon Control Library

The Code

EntryPoint.cs

public abstract class EntryPoint
    {
        [STAThread]
        public static void Main(String[] args)
        {
            RibbonWindow window = new RibbonWindow();
            window.Title = "Demo Ribbon Application";

Create Ribbon

#region setup ribbon
RibbonBar bar = new RibbonBar();

#region clipboard group
RibbonGroupBox rgb = new RibbonGroupBox();
rgb.Text = "Clipboard";
rgb.ShowLabelButton = true;
bar.Children.Add(rgb);

RibbonThreeButtonsGroupLayout tbgl = new RibbonThreeButtonsGroupLayout();
rgb.Children.Add(tbgl);

#region paste
ContextMenu contextMenu = new ContextMenu();
MenuItem m1 = new MenuItem();
m1.Header = "_Paste";
MenuItem m2 = new MenuItem();
m2.Header = "Paste _Special";
MenuItem m3 = new MenuItem();
m3.Header = "Paste as _Hyperlink";
MenuItem m4 = new MenuItem();
m4.Header = "Recent Files";
contextMenu.Items.Add(m1);
contextMenu.Items.Add(m2);
contextMenu.Items.Add(m3);

RibbonDoubleButton rdb = new RibbonDoubleButton();
rdb.ControlID = new Guid("{CFEACF92-062B-4a59-822A-3F6F2B1C9210}");
rdb.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\paste_from_clipboard.png", UriKind.RelativeOrAbsolute));
rdb.Text = "Paste";
rdb.IsDefaultQuickAccessButton = true;
rdb.IsDefaultQuickAccessMenuButton = true;
rdb.SubMenu = contextMenu;
rdb.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("V");

ImageAndTextTip imageAndTextTip = new ImageAndTextTip();
imageAndTextTip.Title = "Example Image Tip";
imageAndTextTip.Text = "This screen tip not only shows a title and some text, " 
   + "but an image as well.";
imageAndTextTip.Image = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\order_now.png", UriKind.RelativeOrAbsolute));
rdb.NormalTip = imageAndTextTip;

//rgb.addRibbonComponent(rdb);
tbgl.Button1 = rdb;
#endregion

#region cut
rdb = new RibbonDoubleButton();
rdb.ControlID = new Guid("{49C6A258-147B-4b77-9E57-0CBA05225031}");
rdb.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\cut.png", UriKind.RelativeOrAbsolute));
rdb.Text = "Cut";
rdb.IsSelected = true;
rdb.IsDefaultQuickAccessButton = true;
rdb.IsDefaultQuickAccessMenuButton = true;

TextOnlyTip textOnlyTip = new TextOnlyTip();
textOnlyTip.Title = "Example Screen Tip";
textOnlyTip.Text = "This is an example screen tip; tips give you help, "
   + "and are required by Microsoft's guidelines. This tip fades in and "
   + "out nicely as would be expected";
rdb.NormalTip = (IScreenTip)textOnlyTip;
rdb.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("X");

tbgl.Button2 = rdb;
#endregion

#region copy
rdb = new RibbonDoubleButton();
rdb.ControlID = new Guid("{0D921F3D-DF58-4d1a-9F88-AC1A9035D38E}");
rdb.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\copy.png", UriKind.RelativeOrAbsolute));
rdb.DisabledImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\copy_disabled.png", UriKind.RelativeOrAbsolute));
rdb.Text = "Copy";
rdb.IsEnabled = false;
rdb.IsDefaultQuickAccessButton = true;
rdb.IsDefaultQuickAccessMenuButton = true;
rdb.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("C");

tbgl.Button3 = rdb;
#endregion

#region wide three stack
RibbonThreeRowsLayout trl = new RibbonThreeRowsLayout();

RibbonThirdLabel rtl = new RibbonThirdLabel();
rtl.ControlID = new Guid("{B3DDCEA3-BF62-4c24-83FD-5CFA0736B152}");
rtl.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\paste_from_clipboard.png", UriKind.RelativeOrAbsolute));
rtl.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("RTL1");
rtl.IsSelected = true;
trl.TopChildren.Add(rtl);

rtl = new RibbonThirdLabel();
rtl.ControlID = new Guid("{D23B54F2-750D-4bdc-A629-029CF12B056A}");
rtl.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\paste_from_clipboard.png", UriKind.RelativeOrAbsolute));
rtl.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("RTL2");
rtl.Text = "Try this";
trl.MiddleChildren.Add(rtl);

#region context menu label
rtl = new RibbonThirdLabel();
rtl.ControlID = new Guid("{886C0404-6360-49d7-8F01-6BC6E06ACF56}");
rtl.IsEnabled = false;
rtl.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\paste_from_clipboard.png", UriKind.RelativeOrAbsolute));
rtl.Text = "Try this";

contextMenu = new ContextMenu();
m1 = new MenuItem();
m1.Header = "Option _1";
m2 = new MenuItem();
m2.Header = "Option _2";
m3 = new MenuItem();
m3.Header = "Option _3";
m4 = new MenuItem();
m4.Header = "Option _4";
contextMenu.Items.Add(m1);
contextMenu.Items.Add(m2);
contextMenu.Items.Add(m3);
contextMenu.Items.Add(m4);

rtl.SubMenu = contextMenu;
rtl.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("RTL3");
trl.BottomChildren.Add(rtl);
#endregion

rgb.Children.Add(trl);
#endregion

#region narrow three stack
trl = new RibbonThreeRowsLayout();
rtl = new RibbonThirdLabel();
rtl.ControlID = new Guid("{CDD8B3AE-C72F-40a5-8159-726ECF99E1B9}");
rtl.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\paste_from_clipboard.png", UriKind.RelativeOrAbsolute));
rtl.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("R4");
trl.TopChildren.Add(rtl);

rtl = new RibbonThirdLabel();
rtl.ControlID = new Guid("{F221E171-9A85-489a-871D-70B6A9048EF4}");
rtl.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\paste_from_clipboard.png", UriKind.RelativeOrAbsolute));
rtl.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("R5");
trl.MiddleChildren.Add(rtl);

rtl = new RibbonThirdLabel();
rtl.ControlID = new Guid("{8D1D07D9-5043-47f7-A27F-B3940D83980D}");
rtl.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\paste_from_clipboard.png", UriKind.RelativeOrAbsolute));
rtl.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("R6");
trl.BottomChildren.Add(rtl);

rgb.Children.Add(trl);
#endregion


rgb = new RibbonGroupBox();
#endregion

#region paragraph group
RibbonTwoRowsLayout trl2 = new RibbonTwoRowsLayout();

#region group 1
RibbonHalfButtonGroup hbg = new RibbonHalfButtonGroup();
hbg.EnforceSelectOne = true;
RibbonHalfButton hb1 = new RibbonHalfButton();
hb1.IsSelected = true;
hb1.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/enter_registration_key.png", UriKind.RelativeOrAbsolute));
hb1.Text = "Half Button 1a";
hb1.IsDefaultQuickAccessMenuButton = true;
hb1.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("1A");
hb1.Clicked += new MouseButtonEventHandler(selectOnClick_Clicked);
RibbonHalfButton hb2 = new RibbonHalfButton();
hb2.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/help.png", UriKind.RelativeOrAbsolute));
hb2.Text = "Half Button 1b";
hb2.IsDefaultQuickAccessMenuButton = true;
RibbonHalfButton hb3 = new RibbonHalfButton();
hb3.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/preview.png", UriKind.RelativeOrAbsolute));
hb3.Text = "Half Button 1b";
hb3.IsDefaultQuickAccessMenuButton = true;
hb3.Clicked += new MouseButtonEventHandler(selectOnClick_Clicked);
hb3.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("1B");
RibbonHalfButton hb4 = new RibbonHalfButton();
hb4.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/save.png", UriKind.RelativeOrAbsolute));
hb4.Text = "Half Button 1d";
hb4.IsDefaultQuickAccessMenuButton = true;
RibbonHalfButton hb5 = new RibbonHalfButton();
hb5.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/about.png", UriKind.RelativeOrAbsolute));
hb5.Text = "Half Button 1c";
hb5.Clicked += new MouseButtonEventHandler(selectOnClick_Clicked);
hb5.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("1C");
hb5.IsDefaultQuickAccessMenuButton = true;
hbg.Children.Add(hb1);
hbg.Children.Add(hb3);
hbg.Children.Add(hb5);

trl2.TopChildren.Add(hbg);
#endregion

#region group 2
hbg = new RibbonHalfButtonGroup();
hb1 = new RibbonHalfButton();
hb1.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/enter_registration_key.png", UriKind.RelativeOrAbsolute));
hb2 = new RibbonHalfButton();
hb2.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/help.png", UriKind.RelativeOrAbsolute));
hb3 = new RibbonHalfButton();
hb3.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/preview.png", UriKind.RelativeOrAbsolute));
hb4 = new RibbonHalfButton();
hb4.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/save.png", UriKind.RelativeOrAbsolute));
hb5 = new RibbonHalfButton();
hb5.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/about.png", UriKind.RelativeOrAbsolute));

hb1.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("2A");
hb2.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("2B");
hb3.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("2C");
hb4.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("2D");
hb5.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("2E");

hbg.Children.Add(hb1);
hbg.Children.Add(hb2);
hbg.Children.Add(hb3);
hbg.Children.Add(hb4);
hbg.Children.Add(hb5);

trl2.TopChildren.Add(hbg);
#endregion

#region group 2
hbg = new RibbonHalfButtonGroup();
hb1 = new RibbonHalfButton();
hb1.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/enter_registration_key.png", UriKind.RelativeOrAbsolute));
hb2 = new RibbonHalfButton();
hb2.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/help.png", UriKind.RelativeOrAbsolute));
hb3 = new RibbonHalfButton();
hb3.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/preview.png", UriKind.RelativeOrAbsolute));
hb4 = new RibbonHalfButton();
hb4.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/save.png", UriKind.RelativeOrAbsolute));
hb5 = new RibbonHalfButton();
hb5.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/about.png", UriKind.RelativeOrAbsolute));

hb1.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("3A");
hb2.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("3B");
hb3.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("3C");
hb5.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("3D");

hb1.Clicked += new MouseButtonEventHandler(toggleSelectedOnClick_Clicked);
hb2.Clicked += new MouseButtonEventHandler(toggleSelectedOnClick_Clicked);
hb3.Clicked += new MouseButtonEventHandler(toggleSelectedOnClick_Clicked);
hb4.Clicked += new MouseButtonEventHandler(toggleSelectedOnClick_Clicked);
hb5.Clicked += new MouseButtonEventHandler(toggleSelectedOnClick_Clicked);

hbg.Children.Add(hb1);
hbg.Children.Add(hb2);
hbg.Children.Add(hb3);
hbg.Children.Add(hb5);

trl2.BottomChildren.Add(hbg);
#endregion

#region group 3
hbg = new RibbonHalfButtonGroup();
hb1 = new RibbonHalfButton();
hb1.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons/enter_registration_key.png", UriKind.RelativeOrAbsolute));

hbg.Children.Add(hb1);

trl2.BottomChildren.Add(hbg);
#endregion

#region group 4
hbg = new RibbonHalfButtonGroup();

RibbonHalfComboBox hcb = new RibbonHalfComboBox();
ComboBox cb = new ComboBox();

ComboBoxItem cbi1 = new ComboBoxItem();
cbi1.Content = "Combo 1";
ComboBoxItem cbi2 = new ComboBoxItem();
cbi2.Content = "Combo 2";
ComboBoxItem cbi3 = new ComboBoxItem();
cbi3.Content = "Combo 3";
ComboBoxItem cbi4 = new ComboBoxItem();
cbi4.Content = "Combo 4";

cb.Items.Add(cbi1);
cb.Items.Add(cbi2);
cb.Items.Add(cbi3);
cb.Items.Add(cbi4);

hcb.setComboBox(cb);
hbg.Children.Add(hcb);

hb4 = new RibbonHalfButton();
hb4.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\save.png"));
hbg.Children.Add(hb4);

trl2.BottomChildren.Add(hbg);
#endregion


rgb = new RibbonGroupBox();
rgb.Text = "Font";
rgb.Children.Add(trl2);
RibbonGroupBox font = new RibbonGroupBox();
font = rgb;
bar.Children.Add(rgb);
#endregion

#region standard button group
rgb = new RibbonGroupBox();
rgb.Text = "Full Buttons";
bar.Children.Add(rgb);

Button b1 = new Button();
b1.Content = "BUTTON 1";
b1.Height = 80;
b1.Margin = new Thickness(0.5);

Button b2 = new Button();
b2.Content = "BUTTON 2";
b2.Height = 80;
b2.Margin = new Thickness(0.5);

Button b3 = new Button();
b3.Content = "BUTTON 3";
b3.Height = 80;
b3.Margin = new Thickness(0.5);

//rgb.addRibbonComponent(b1);
//rgb.addRibbonComponent(b2);
//rgb.addRibbonComponent(b3);

RibbonButton rb = new RibbonButton();
rb.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\paste_from_clipboard.png", UriKind.RelativeOrAbsolute));
rb.Text = "Button";
rb.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("BA");
rb.IsSelected = true;
rgb.Children.Add(rb);

RibbonDoubleButton db2 = new RibbonDoubleButton();
db2.NormalImage = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\paste_from_clipboard.png", UriKind.RelativeOrAbsolute));
db2.Text = "Compare";
db2.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("BB");
db2.IsEnabled = false;
rgb.Children.Add(db2);
#endregion

#region styles group
rgb = new RibbonGroupBox();
rgb.Text = "Styles";
bar.Children.Add(rgb);

RibbonPreviewBoxes rpb = new RibbonPreviewBoxes();

RibbonPreviewBox prb = new RibbonPreviewBox();
prb.Image = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\help.png", UriKind.RelativeOrAbsolute));
prb.Text = "Help";
rpb.Children.Add(prb);
prb = new RibbonPreviewBox();
prb.Image = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\enter_registration_key.png", UriKind.RelativeOrAbsolute));
prb.Text = "Key";
rpb.Children.Add(prb);
prb = new RibbonPreviewBox();
prb.Image = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\preview.png", UriKind.RelativeOrAbsolute));
prb.Text = "Preview";
rpb.Children.Add(prb);
prb = new RibbonPreviewBox();
prb.Image = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\print.png", UriKind.RelativeOrAbsolute));
prb.Text = "Print";
rpb.Children.Add(prb);
prb = new RibbonPreviewBox();
prb.Image = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\redo.png", UriKind.RelativeOrAbsolute));
prb.Text = "Redo";
rpb.Children.Add(prb);
prb = new RibbonPreviewBox();
prb.Image = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\save.png", UriKind.RelativeOrAbsolute));
prb.Text = "Save";
rpb.Children.Add(prb);
prb = new RibbonPreviewBox();
prb.Image = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\undo.png", UriKind.RelativeOrAbsolute));
prb.Text = "Undo";
rpb.Children.Add(prb);
prb = new RibbonPreviewBox();
prb.Image = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\yes.png", UriKind.RelativeOrAbsolute));
prb.Text = "Yes";
rpb.Children.Add(prb);
prb = new RibbonPreviewBox();
prb.Image = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\about.png", UriKind.RelativeOrAbsolute));
prb.Text = "About";
rpb.Children.Add(prb);
prb = new RibbonPreviewBox();
prb.Image = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\cancel.png", UriKind.RelativeOrAbsolute));
prb.Text = "Cancel";
rpb.Children.Add(prb);
prb = new RibbonPreviewBox();
prb.Image = new BitmapImage(new Uri(Environment.CurrentDirectory 
   + @"\\Standard Icons\e-mail.png", UriKind.RelativeOrAbsolute));
prb.Text = "E-mail";
rpb.Children.Add(prb);

rgb.Children.Add(rpb);
#endregion

//ribbonGrid.Children.Add(bar);

bar.Text = "Home";
bar.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("H");
window.RibbonController.Ribbons.Add(bar);

RibbonBar rb1 = new RibbonBar();
rb1.Text = "Insert";
rb1.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("N");
window.RibbonController.Ribbons.Add(rb1);

RibbonBar rb2 = new RibbonBar();
rb2.Text = "Page Layout";
rb2.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("P");
window.RibbonController.Ribbons.Add(rb2);

RibbonBar rb3 = new RibbonBar();
rb3.Text = "References";
rb3.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("S");
window.RibbonController.Ribbons.Add(rb3);

RibbonBar rb4 = new RibbonBar();
rb4.Text = "Mailings";
rb4.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("M");
window.RibbonController.Ribbons.Add(rb4);

RibbonBar rb5 = new RibbonBar();
rb5.Text = "Review";
rb5.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("R");
window.RibbonController.Ribbons.Add(rb5);

RibbonBar rb6 = new RibbonBar();
rb6.Text = "View";
rb6.KeyboardAccessCombination = new RibbonKeyboardAccessKeyCombination("W");
window.RibbonController.Ribbons.Add(rb6);
#endregion

Create application menu

            #region setup application menu
            window.ApplicationMenu.MenuButtons.Add(new ApplicationMenuButton() 
                { 
                    Text = "Button 1", 
                    Image = new BitmapImage(
                        new Uri(
                            Environment.CurrentDirectory 
                            + @"\\Standard Icons\e-mail.png", UriKind.RelativeOrAbsolute
                            )
                            ) 
                });

            ApplicationMenuButtonPopup ambp = new ApplicationMenuButtonPopup();
            ambp.Text = "Button 2 Sub-Menu";
            ambp.Items.Add(new ApplicationMenuButtonPopupItem()
            {
                TitleText = "Title 1",
                DescriptionText = "Here is the description for item 1",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\yes.png", UriKind.RelativeOrAbsolute
                        )
                        )
            });
            ambp.Items.Add(new ApplicationMenuButtonPopupItem()
            {
                TitleText = "Title 2",
                DescriptionText = "Here is the description for item 2",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\no.png", UriKind.RelativeOrAbsolute
                        )
                        )
            });
            ambp.Items.Add(new ApplicationMenuButtonPopupItem()
            {
                TitleText = "Title 3",
                DescriptionText = "Here is the description for item 3, this description is really very long...",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\e-mail.png", UriKind.RelativeOrAbsolute
                        )
                        )
            });

            window.ApplicationMenu.MenuButtons.Add(new ApplicationMenuButton()
            {
                Text = "Button 2",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\yes.png", UriKind.RelativeOrAbsolute
                        )
                        ),
                ShowDivider = true,
                ShowPopupArrow = true,
                PopupMenu = ambp
            });

            ApplicationMenuButtonPopup ambp2 = new ApplicationMenuButtonPopup();
            ambp2.Text = "Button 3 Popup Menu, Requires scrolling";
            ambp2.Items.Add(new ApplicationMenuButtonPopupItem()
            {
                TitleText = "Item 1",
                DescriptionText = "Here is the description for item 1",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\no.png", UriKind.RelativeOrAbsolute
                        )
                        )
            });
            ambp2.Items.Add(new ApplicationMenuButtonPopupItem()
            {
                TitleText = "Item 2",
                DescriptionText = "Here is the description for item 2",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\no.png", UriKind.RelativeOrAbsolute
                        )
                        )
            });
            ambp2.Items.Add(new ApplicationMenuButtonPopupItem()
            {
                TitleText = "Item 3",
                DescriptionText = "Here is the description for item 3",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\no.png", UriKind.RelativeOrAbsolute
                        )
                        )
            });
            ambp2.Items.Add(new ApplicationMenuButtonPopupItem()
            {
                TitleText = "Item 4",
                DescriptionText = "Here is the description for item 4",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\no.png", UriKind.RelativeOrAbsolute
                        )
                        )
            });
            ambp2.Items.Add(new ApplicationMenuButtonPopupItem()
            {
                TitleText = "Item 5",
                DescriptionText = "Here is the description for item 5",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\no.png", UriKind.RelativeOrAbsolute
                        )
                        )
            });
            ambp2.Items.Add(new ApplicationMenuButtonPopupItem()
            {
                TitleText = "Item 6",
                DescriptionText = "Here is the description for item 6",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\no.png", UriKind.RelativeOrAbsolute
                        )
                        )
            });
            ambp2.Items.Add(new ApplicationMenuButtonPopupItem()
            {
                TitleText = "Item 7",
                DescriptionText = "Here is the description for item 7",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\no.png", UriKind.RelativeOrAbsolute
                        )
                        )
            });
            ambp2.Items.Add(new ApplicationMenuButtonPopupItem()
            {
                TitleText = "Item 8",
                DescriptionText = "Here is the description for item 8",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\no.png", UriKind.RelativeOrAbsolute
                        )
                        )
            });

            window.ApplicationMenu.MenuButtons.Add(new ApplicationMenuButton()
            {
                Text = "Button 3",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\enter_registration_key.png", UriKind.RelativeOrAbsolute
                        )
                        ),
                ShowPopupArrow = true,
                PopupMenu = ambp2
            });

            window.ApplicationMenu.MenuButtons.Add(new ApplicationMenuButton()
            {
                Text = "Button 4",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\save.png", UriKind.RelativeOrAbsolute
                        )
                        )
            });

            window.ApplicationMenu.MenuButtons.Add(new ApplicationMenuButton()
            {
                Text = "Button 5",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\about.png", UriKind.RelativeOrAbsolute
                        )
                        ),
                ShowDivider = true
            });

            window.ApplicationMenu.MenuButtons.Add(new ApplicationMenuButton()
            {
                Text = "Button 6",
                Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\cancel.png", UriKind.RelativeOrAbsolute
                        )
                        )
            });

            BitmapImage pinnedImageSource = new BitmapImage(new Uri(Environment.CurrentDirectory
                        + @"\\Graphics\Standard Icons\pinned.png", UriKind.RelativeOrAbsolute));
            BitmapImage unPinnedImageSource = new BitmapImage(new Uri(Environment.CurrentDirectory 
                        + @"\\Graphics\Standard Icons\unpinned.png", UriKind.RelativeOrAbsolute));

            window.ApplicationMenu.DocumentButtons.Add(new ApplicationDocument() { 
                           Text = "Document 1", PinnedImage = pinnedImageSource, 
                              UnPinnedImage = unPinnedImageSource });
            window.ApplicationMenu.DocumentButtons.Add(new ApplicationDocument() { 
                           Text = "Document 2", PinnedImage = pinnedImageSource, 
                              UnPinnedImage = unPinnedImageSource });
            window.ApplicationMenu.DocumentButtons.Add(new ApplicationDocument() { 
                           Text = "Document 3", PinnedImage = pinnedImageSource, 
                              UnPinnedImage = unPinnedImageSource });
            window.ApplicationMenu.DocumentButtons.Add(new ApplicationDocument() { 
                           Text = "Document 4", PinnedImage = pinnedImageSource, 
                              UnPinnedImage = unPinnedImageSource });
            window.ApplicationMenu.DocumentButtons.Add(new ApplicationDocument() { 
                           Text = "Document 5", PinnedImage = pinnedImageSource, 
                              UnPinnedImage = unPinnedImageSource });
            window.ApplicationMenu.DocumentButtons.Add(new ApplicationDocument() { 
                           Text = "Document 6", PinnedImage = pinnedImageSource, 
                              UnPinnedImage = unPinnedImageSource });
            window.ApplicationMenu.DocumentButtons.Add(new ApplicationDocument() { 
                           Text = "Document 7", PinnedImage = pinnedImageSource, 
                              UnPinnedImage = unPinnedImageSource });

            window.ApplicationMenu.MasterApplicationButtons.Add(new ApplicationMasterButton() { 
                            Text = "Exit Application", 
                            Image = new BitmapImage(
                                        new Uri(Environment.CurrentDirectory + 
                                                    @"\\Graphics\Standard Icons\no.png", UriKind.RelativeOrAbsolute)) 
                            });
            window.ApplicationMenu.MasterApplicationButtons[0].Clicked += new MouseButtonEventHandler(EntryPoint_Clicked);

            window.ApplicationButton.Image = new BitmapImage(
                    new Uri(
                        Environment.CurrentDirectory
                        + @"\\Standard Icons\order_now.png", UriKind.RelativeOrAbsolute
                        )
                        );
            #endregion

Finish up

window.QuickAccessToolbar.resetToDefault(window.RibbonController);

#region window content
StackPanel sPanel = new StackPanel();
sPanel.Orientation = Orientation.Vertical;
sPanel.Children.Add(new StyleButtons());
sPanel.Children.Add(new QATPersistanceButtons(window.RibbonController, window.QuickAccessToolbar));
window.Content = sPanel;
#endregion


Application app = new Application();
app.Run(window);

Event handlers

private static void toggleSelectedOnClick_Clicked(object sender, MouseButtonEventArgs e)
{
    ((IRibbonControl)sender).IsSelected = !((IRibbonControl)sender).IsSelected;
}

private static void selectOnClick_Clicked(object sender, MouseButtonEventArgs e)
{
    ((IRibbonControl)sender).IsSelected = true;
}

StyleButtons.xaml

<UserControl x:Class="CIRIP_V2.StyleButtons"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
        <Grid VerticalAlignment="Center" HorizontalAlignment="Center">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <Button Name="blueButton" Grid.Column="0" Margin="5" 
        Click="blueButton_Click">Blue</Button>
            <Button Name="grayButton" Grid.Column="1" Margin="5" 
        Click="grayButton_Click">Gray</Button>
            <Button Name="blackButton" Grid.Column="2" Margin="5" 
        Click="blackButton_Click">Black</Button>
            <Button Name="greenButton" Grid.Column="3" Margin="5" 
        Click="greenButton_Click">Green</Button>
        </Grid>
    </Grid>
</UserControl>

StyleButtons.xaml.cs

    public partial class StyleButtons : UserControl
    {
        public StyleButtons()
        {
            InitializeComponent();
        }

        private void blueButton_Click(object sender, RoutedEventArgs e)
        {
            RibbonStyleHandler.reStyle(RibbonStyleHandler.Style.Blue);
        }

        private void grayButton_Click(object sender, RoutedEventArgs e)
        {
            RibbonStyleHandler.reStyle(RibbonStyleHandler.Style.Gray);
        }

        private void blackButton_Click(object sender, RoutedEventArgs e)
        {
            RibbonStyleHandler.reStyle(RibbonStyleHandler.Style.Black);
        }

        private void greenButton_Click(object sender, RoutedEventArgs e)
        {
            RibbonStyleHandler.reStyle(RibbonStyleHandler.Style.Green);
        }
    }

QATPersistanceButtons.xml

<UserControl x:Class="RibbonDemonstration.QATPersistanceButtons"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
   <Grid>
      <Grid VerticalAlignment="Center" HorizontalAlignment="Center">
         <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
         </Grid.ColumnDefinitions>

      <Button Name="loadButton" Grid.Column="1" Margin="5" 
         Click="loadButton_Click">Save QAT</Button>

      <Button Name="saveButton" Grid.Column="2" Margin="5" 
         Click="saveButton_Click">Load QAT</Button>

      </Grid> 
   </Grid>
</UserControl>

QATPersistanceButtons.xaml.cs

Note that load and save event handler names are the incorrect way around; oops!

public partial class QATPersistanceButtons : UserControl
{
   private QuickAccessToolbar toolbar = null;
   private RibbonController controller = null;

   public QATPersistanceButtons(RibbonController controller, QuickAccessToolbar toolbar)
   {
      InitializeComponent();
      this.controller = controller;
      this.toolbar = toolbar;
   }

   private void loadButton_Click(object sender, RoutedEventArgs e)
   {
      StreamWriter writer = null;
      try
      {
         writer = new StreamWriter(Environment.CurrentDirectory + @"\qat.config");
         writer.AutoFlush = true;

         List current = toolbar.getCurrentButtonControlIDs();
         for (int i = 0; i < current.Count; i++)
         {
            writer.WriteLine(current[i].ToString());
         }
         writer.Flush();
      }
      catch (Exception err)
      {
         MessageBox.Show("Failed to save file " + err.ToString(), 
            "Error", MessageBoxButton.OK);
      }
      finally
      {
         if (writer != null)
         {
            writer.Close();
         }
      }
   }

   private void saveButton_Click(object sender, RoutedEventArgs e)
   {
      MessageBox.Show("This only works for clipboard group QAT buttons, "
         + "anything other will be ignore.\r\n\r\nBasically I havn't added a "
         + "value to .ControlID to all the controls", 
         "Warning", MessageBoxButton.OK, 
         MessageBoxImage.Information);
   
      StreamReader reader = null;
      try
      {
         reader = new StreamReader(Environment.CurrentDirectory + @"\qat.config");

         List current = new List();
         while (!reader.EndOfStream)
         {
            current.Add(new Guid(reader.ReadLine()));
         }

         toolbar.loadButtons(current, controller);
      }
      catch (Exception err)
      {
         MessageBox.Show("Failed to save file " + err.ToString(), "Error", MessageBoxButton.OK);
      }
      finally
      {
         if (reader != null)
         {
            reader.Close();
         }
      }
   }
}

General Code Structure

  1. Create RibbonWindow object
  2. Set window title via .Title
  3. Create Ribbon via .RibbonController
  4. Update Quick Access Toolbar to show default content via window.QuickAccessToolbar.resetToDefault(window.RibbonController); where window is the RibbonWindow object
  5. Create window content and link via .Content
  6. Show the window via the Application object

Notes

Appologies if the article is a little wide, but please don't ask me to make it narrower!

Please do NOT moan this article has no information on how the ribbon itself works.... this article is showing the demo source and nothing else.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here