【问题标题】:RibbonComboBox doesn't display selected itemRibbonComboBox 不显示所选项目
【发布时间】:2015-03-02 16:26:53
【问题描述】:

非常简单的程序。也许太简单了? 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 的参考。

【问题讨论】:

    标签: c# wpf combobox ribbon


    【解决方案1】:

    为什么没有 SelectedItem 绑定集?

    SelectedItem = {Binding mySelectedBaud}
    

    How to databind SelectedItem of RibbonComboBox

    【讨论】:

    • 这就是我遗漏的内容。一般是 WPF 新手,所以我仍在学习正在进行的绑定。谢谢!
    • 是的,我还在学习,学习曲线很陡峭,尤其是使用 Xaml。继续插电,你会到达那里
    【解决方案2】:

    我想我可能已经找到了另一个答案:RibbonGallery 控件上的 IsSynchronizedWithCurrentItem="True" 正确设置了 SelectedItem

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多