-->

Bind RibbonComboBox.SelectionBoxItem

2019-08-04 07:23发布

问题:

I'm trying to bind the item selected in a RibbonComboBox to a property of an object. The problem I'm encountering is that the RibbonComboBox.SelectionBoxItem only provides a get accessor; therefore, I cannot bind it to anything in the XAML.

Any ideas how to bind the item to the property of an object? I could use a regular ComboBox is there another more appropriate control?

xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"

<ribbon:RibbonComboBox
    ItemsSource="{Binding Source={StaticResource CollectionOfPossibleChoices}}"/
    SelectionBoxItem="{Binding Path=PropertyToBindTo}"/> <!--Not valid-->

回答1:

RibbonComboBox is unlike ComboBox (which i, also, find confusing). Try this;

<ribbon:RibbonComboBox>
    <ribbon:RibbonGallery SelectedItem="{Binding Path=PropertyToBindTo}">
        <ribbon:RibbonGalleryCategory ItemsSource="{Binding Source={StaticResource CollectionOfPossibleChoices}}" />
    </ribbon:RibbonGallery>
</ribbon:RibbonComboBox>

MSDN Reference