RibbonComboBox不显示所选项目

时间:2015-03-02 16:26:53

标签: c# wpf combobox ribbon

非常简单的程序。也许太简单了? XMAL:

<RibbonComboBox x:Name="cbxRibbonCommsGroupBaud"  LargeImageSource="Resource/Cheetah.png">
   <RibbonGallery Name="RBaudGGallery" SelectionChanged="RBaudGGallery_OnSelectionChanged">
       <RibbonGalleryCategory Name="RBaudGGalleryC" ItemsSource="{Binding}"></RibbonGalleryCategory>
   </RibbonGallery>
</RibbonComboBox>

背后的代码:

private int[] baudRateList = { 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600 };
cbxRibbonCommsGroupBaud.Items.Clear();
cbxRibbonCommsGroupBaud.ItemsSource = baudRateList;

当我运行程序时,项目在组合框下拉,但是当我选择项目时,它不会停留并且框显示为空。此外,从不调用RBaudGGallery_OnSelectionChanged。所以我错过了一些东西,但不知道是什么,因为其他组合框工作正常,不在功能区中。我正在使用System.Windows.Controls.Ribbon的参考。

2 个答案:

答案 0 :(得分:2)

为什么你没有SelectedItem绑定集?

SelectedItem = {Binding mySelectedBaud}

How to databind SelectedItem of RibbonComboBox

答案 1 :(得分:0)

我想我可能找到了另一个答案:IsSynchronizedWithCurrentItem =&#34; True&#34;在RibbonGallery控件上正确设置SelectedItem

<RibbonGallery 
  IsSynchronizedWithCurrentItem="True" 
  SelectedItem="{Binding SelectedRule, Mode=TwoWay}" 
  x:Name="RulesItems" >
      <RibbonGalleryCategory 
             ItemsSource="{Binding RulesCollection, Mode=TwoWay}"          
             DisplayMemberPath="DisplayName" />
</RibbonGallery>