Bind RibbonComboBox.SelectionBoxItem

风格不统一 提交于 2019-12-11 11:16:49

问题


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



来源:https://stackoverflow.com/questions/6700696/bind-ribboncombobox-selectionboxitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!