If you search this website before you post questions, you can find good answers... Take a look at this post and this post.
UPDATE >>>
The How to set SelectedItem on a RibbonComboBox using MVVM? post that I gave you a link for has a complete solution for you. Basically the answer is this:
Whatever object that you set as the RibbonGallery.DataContext
should have a collection property to bind to the RibbonGalleryCategory.ItemsSource
property and a property of the same type as the collection items to bind to the RibbonGallery SelectedItem
property.
Let's say that your selected item property is called SelectedItem
. You will then be able to set the SelectedItem
property of the object that you set as the RibbonGallery.DataContext
to an item from the collection and the binding will change the selected item in the RibbonGallery
UI.
Note that if you are using objects as your gallery data types (as opposed to primitives like string
, etc.), then this will only work if you set your SelectedItem
property to an actual item from the collection and not just one with the same values. This can be easily achieved if your data object has a property with unique values by the following:
DataContextData.SelectedItem = DataContextData.CollectionData.Where(d => d.Id ==
itemToSelect.Id).Single();
If that still hasn't helped, I did a quick search online and found a complete solution that you can download and examine at your leisure in the How do I add Galleries to my Ribbon? post at 'The official blog of the Windows Presentation Foundation Team'. It shows a good example of the method that I just described.