Spruce up your next application with the WPF Ribbon


Microsoft Office 2007 delivered a bold replacement for
the tired menu bar known simply as the Ribbon.  Up
until recently, the Ribbon was exclusive to Microsoft
applications; however, Microsoft has now made the
WPF(Windows Presentation Foundation) Ribbon available
through the Office UI Licensing
This license in effect allows you to incorporate the WPF
Ribbon as well as the Office 2007 styling into your
application. I should point out, that you will need to
register to download the WPF Ribbon control and essentially
agree not to create an Office 2007 competitive application.
Using the WPF Ribbon within your application provides the
following UI elements:

  • The Application Button is the round button in the upper
    left. Its purpose is to provide access to the Application
    Menu which includes one or more menu items.

  • The Quick Access Toolbar provides convenient access to
    common functions.

  • Tabs provide high level grouping for items within the
    Ribbon. Within each tab, multiple Groups exists to provide
    further categorization. Inside each Group is where the
    individual controls exist.

After downloading the Ribbon Control, create a WPF
Application project and add a reference to the
RibbonControlLibrary. Next, we need to modify
the existing Window to start creating the Ribbon. To get
started, we need to modify the XAML(eXtensible Application
Markup Language) to modify the window and create a blank
Ribbon. The XAML to create the window with the empty ribbon
is listed below:

<my:RibbonWindow x_Class=”WPFRibbonExample.Window1″

Title=”WPF Ribbon Example”
Height=”374″ Width=”633″

<ResourceDictionary Source=”/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml”/>

<my:Ribbon DockPanel.Dock=”Top” Name=”ribbon1″ Height=”138″ Title=”WPF Ribbon Example” VerticalAlignment=”Top”>


If you execute the application at this point, you should
see the screen as shown below:

Empty Ribbon
Click here for larger image

Figure 1 – Empty Ribbon

This basic XAML above is slightly different from a
standard Window. The window tag itself is replaced with a
RibbonWindow which provides additional functionlity
necessary for the Ribbon UI. Next we pull in the Office 2007
Blue styling and finally create a blank Ribbon inside a
DockPanel. Next we’ll focus on creating the necessary
elements within the Ribbon. Insert the following XAML inside
the Ribbon tag.

<my:RibbonTab Label=”File”>
<my:RibbonTab Label=”View” /”>

At this point, the ribbon should show 2 tabs, File and
View as shown below.

File and View Tabs
Figure 2 – File and View Tabs

Next we create a group and finally the individual
controls. The following XAML snippet should be inserted into
the RibbonTab tag.

<my:RibbonGroup Name=”FileOperations”>
<my:RibbonCommand LabelTitle=”File Operations” ></my:RibbonCommand>

This will create an empty File Operations Group and
assign a label to it. This is done through the RibbonCommand
class. Next we need to start creating buttons within the
group. Before we start creating buttons, it is a good idea
to start planning the commands for the Ribbon. Each command
the ribbon will perform should be created as a Ribbon
Resource so it can be reused for buttons on the Ribbon and
Quick Access toolbar or within the Application Menu. Below
is a simple Open RibbonCommand Resource which
is to be inserted within the Ribbon tag.

<my:RibbonCommand x_Key=”OpenCommand”
Executed=”OpenCommand_Executed” />

More by Author

Must Read