Ribbon Control in WPF 4.5

WPF 4.5 has been extended by a new feature called Ribbon control that hosts quick access to the toolbar, Application Menu and tabs. The Ribbon is a way to organize the related commands shown as control on the Ribbon so that they are easier to find. The controls are organized as groups along the horizontal strip at the top of application windows. Related groups are organized into tabs.

After using this feature there is no need to incorporate separate downloads for our project.

The following shows how to use a Ribbon Control in a WPF application.

wcf application

Step 1

First create a WPF application.

Step 2

By default, a new WPF project does not include the library reference to start using the Ribbon control and related sub-controls. So before adding a Ribbon control to a project we need to add a reference to the system.

The reference for the Ribbon control is "System.Windows.Controls.Ribbon".

So to add this reference we need to use the following procedure.

Go to the project of your WPF application in Solution Explorer then right-click on References then choose Add referencethen activate the check box for "System.Windows.Controls.Ribbon".

reference

Step 3

The we need to  add a new Ribbon Control to the project.

After adding this reference we can input the XAML code to define a new Ribbon control and we will see it in the XAML preview. This is an empty Ribbon.

XAML code

Example: We can understand it by adding many sub-controls.

Add a folder named "images" to your WPF application then drag some images to it (I just dragged 3 images for making a short application).

Wpf application

The purpose of adding these images is that the Ribbon Control usees these images as icons inside the application.

Procedure to make this application

Step 1

Locate an image (treated as a Help icon) at the right hand side of the page.

html code

show image

Step 2

Add a quick Access toolbar to the left corner as in the following:

quick Access toolbar

toolbar at left corner

Step 3

Create an application menu at the bottom of the page as in the following:

application menu code

bottom of the page

Step 4

Create a Home clipboard and copy and paste a button to the existing application.

Home clipboard code
Home clipboard

Step 5

Add a Home colors group to the page as in the following:

Home colors code

Step 6

Now add a Ribbon tab launch for #2:

adding a Ribbon

adding a Ribbon image

The following is the final code for this application:

  1. <Window x:Class="WpfApplication3.MainWindow"  
  2.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  3.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
  4.         Title="MainWindow" Height="350" Width="525">  
  5.     <Grid>  
  6.         
  7.             <Ribbon x:Name="Ribbon" SelectedIndex="0">  
  8.             <!-- Help Pane, located at the right-hand side -->  
  9.             <Ribbon.HelpPaneContent>  
  10.                 <RibbonButton SmallImageSource="Images\Tulips.jpg" />  
  11.             </Ribbon.HelpPaneContent>  
  12.             <!-- Quick Access Toolbar - located at the upper-left corner -->  
  13.             <Ribbon.QuickAccessToolBar>  
  14.                 <RibbonQuickAccessToolBar>  
  15.                     <RibbonButton x:Name ="Save" SmallImageSource="Images\Desert.jpg" />  
  16.                     <RibbonSplitButton x:Name ="Undo" SmallImageSource="Images\Tulips.jpg" >  
  17.                         <RibbonSplitMenuItem Header="Undo action #1" />  
  18.                         <RibbonSplitMenuItem Header="Undo action #2" />  
  19.                         <RibbonSplitMenuItem Header="Undo action #3" />  
  20.                     </RibbonSplitButton>  
  21.                     <RibbonSplitButton x:Name="Redo" SmallImageSource="Images\Desert.jpg" >  
  22.                         <RibbonSplitMenuItem Header="Redo action #1" />  
  23.                         <RibbonSplitMenuItem Header="Redo action #2" />  
  24.                     </RibbonSplitButton>  
  25.                 </RibbonQuickAccessToolBar>  
  26.             </Ribbon.QuickAccessToolBar>  
  27.             <!-- Application Menu, located at the left-hand side (down arrow) -->  
  28.             <Ribbon.ApplicationMenu>  
  29.                 <RibbonApplicationMenu KeyTip="F">  
  30.                     <RibbonApplicationMenuItem Header="Options" ImageSource="Images\Tulips.jpg" />  
  31.                     <RibbonApplicationMenuItem Header="Exit" ImageSource="Images\Tulips.jpg" />  
  32.                 </RibbonApplicationMenu>  
  33.             </Ribbon.ApplicationMenu>  
  34.             <!-- Ribbon Tab #1: Home -->  
  35.             <RibbonTab Header="Home" KeyTip="H" >  
  36.                 <!-- Home/Clipboard group-->  
  37.                 <RibbonGroup x:Name="ClipboardGroup" Header="Clipboard">  
  38.                     <RibbonMenuButton LargeImageSource="Images\Tulips.jpg" Label="Paste" KeyTip="V">  
  39.                         <RibbonMenuItem ImageSource="Images\Tulips.jpg" Header="Keep Text Only" KeyTip="T"/>  
  40.                         <RibbonMenuItem ImageSource="Images\Tulips.jpg" Header="Paste Special..." KeyTip="S"/>  
  41.                     </RibbonMenuButton>  
  42.                     <RibbonButton SmallImageSource="Images\Tulips.jpg" Label="Cut" KeyTip="X" />  
  43.                     <RibbonButton SmallImageSource="Images\Tulips.jpg" Label="Copy" KeyTip="C" />  
  44.                     <RibbonButton SmallImageSource="Images\Tulips.jpg" Label="Format Painter" KeyTip="FP" />  
  45.                 </RibbonGroup>  
  46.                 <!-- Home/Colors group-->  
  47.                 <RibbonGroup x:Name="Color" Header="Colors">  
  48.                     <RibbonRadioButton LargeImageSource="Images\Tulips.jpg" Label="Red" KeyTip="R" IsChecked="True"/>  
  49.                     <RibbonRadioButton LargeImageSource="Images\Tulips.jpg" Label="Green" KeyTip="G"/>  
  50.                     <RibbonRadioButton LargeImageSource="Images\Tulips.jpg" Label="Blue" KeyTip="B"/>  
  51.                 </RibbonGroup>  
  52.             </RibbonTab>  
  53.             <!-- Ribbon Tab #2: Launch -->  
  54.             <RibbonTab Header="Launch" KeyTip="L">  
  55.                 <!-- Launch/Applications group-->  
  56.                 <RibbonGroup x:Name="DesktopApplication" Header="Desktop Applications">  
  57.                 </RibbonGroup>  
  58.                 <!-- Launch/Games group-->  
  59.                 <RibbonGroup x:Name="App" Header="Apps">  
  60.                 </RibbonGroup>  
  61.                 </RibbonTab>  
  62.         </Ribbon>  
  63.     </Grid>  
  64. </Window>