Bind RibbonComboBox.SelectionBoxItem

2019-08-04 07:10发布

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条回答
对你真心纯属浪费
2楼-- · 2019-08-04 07:42

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

查看更多
登录 后发表回答