Click here to Skip to main content
12,450,101 members (48,382 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

19.4K views
2 bookmarked
Posted

Ribbon (WPF) - RibbonComboBox

, 11 Sep 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Ribbon (WPF) - ribbon:RibbonComboBox
Howto use the ribbon:RibbonCombobox

The main question is how do I retrieve the selectedItem from the ribbonComboBox.
The answer is in the "naming" of the XAML elements and using the correct element-properties.

Step 1) Mainwindow.xaml
<wrappanel>
  <ribbon:ribboncombobox selectionboxwidth="100">
     <ribbon:ribbongallery x:name="fontsComboBox">
                SelectionChanged="RibbonGallery_SelectionChanged">

Step 2) Mainwindow.xaml.cs
public MainWindow()
{
    InitializeComponent();
    InitializeFonts();
}
public void InitializeFonts()
{
    fonts.ItemsSource = Fonts.SystemFontFamilies;
    fontsComboBox.SelectedItem = "Arial";
 
    for (double i = 8; i < 48; i += 2)
    {
         fontSize.Items.Add(i);
     }
     fontSizeComboBox.SelectedItem = "8";
}

Step 3) The SelectionChanged
private void RibbonGallery_SelectionChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
    RibbonGallery source = e.OriginalSource as RibbonGallery;
    if (source == null) return;
    switch (source.Name)
    {
       case "fontsComboBox":
         //change the font face
         _documentManager.ApplyToSelection(
                               TextBlock.FontFamilyProperty, 
                               source.SelectedItem);
          break;
       case "fontSizeComboBox":
        //Change the font size
         _documentManager.ApplyToSelection(
                              TextBlock.FontSizeProperty, 
                              source.SelectedItem);
         break;
    }
}
In short, the RibbonGallery contains the SelectionChanged method and the RibbonGalleryCategory contain the ItemSource.

fonts.ItemsSource = Fonts.SystemFontFailies can also be included directly into the XAML code as ItemSource = {x:Static Fonts.SystemFontFamilies}

Finally, some useful links:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

kribo
Software Developer
Belgium Belgium
Developer within C#, Dynamics NAV (Navision), Php environments.

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160826.1 | Last Updated 11 Sep 2011
Article Copyright 2011 by kribo
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid