2015-03-02 91 views
0

非常簡單的程序。也許太簡單了? XMAL:RibbonComboBox不顯示選定的項目

<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

爲什麼你沒有SelectedItem綁定集?

SelectedItem = {Binding mySelectedBaud} 

How to databind SelectedItem of RibbonComboBox

+0

這就是我離開了。總的來說,WPF是新手,所以我仍然在學習繼續進行的綁定。謝謝! – 2015-03-02 18:20:41

+0

是的,我還在學習,Xaml的學習曲線特別陡峭。不斷堵塞,你會到達那裏 – Hardgraf 2015-03-03 12:29:54

0

我想我可能已經找到另一個答案:IsSynchronizedWithCurrentItem在RibbonGallery控制= 「真」 設置的SelectedItem正確

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