RibbonComboBox SelectionChanged throws cast exception

Jan 28, 2009 at 3:50 PM

I just ran into a strange error using the RibbonComboBox. I am binding a list of ClassA objects to the DataContext of my RibbonComboBox. ClassA has two properties Id (int) and DisplayName (string). The binding seems to work correct. The combo box contains the correct amount of items and displays the correct data.

Now my problem:
Everytime I try to select another element in the RibbonComboBox, my app throws an InvalidCasException ("Unable to cast object of type 'ClassA' to type 'Microsoft.Windows.Controls.Ribbon.RibbonComboBoxItem'.").
I've wired up the SelectionChanged event, which is executed correctly. If I check the SelectedValue (contains the Id field of ClassA) and SelectedItem (contains the ClassA object) property in my SelectionChanged event handler, they contain the expected values. After my event handler was executed the InvalidCastException suddenly appears.

My XAML definition:
 < r:RibbonComboBox Name="cbxTerms" ItemsSource="{Binding}" SelectionChanged="cbxTerms_SelectionChanged" DisplayMemberPath="DisplayName" SelectedValuePath="Id" Width="100" Text="{Binding ElementName=cbxTerms, Path=SelectedItem.Content}" />

Do I miss something?

If I bind a list of RibbonComboBoxItems (Content = DisplayName of ClassA) to the ItemsSource property the selection change works properly. But then I have to find the Id of ClassA in code again. Instead of just taking the SelectedItem with the Id-value in it.
Is it possible at all to bind other objects then RibbonComboBoxItem to a RibbonComboBox?

Thanks for your answers.

Feb 5, 2009 at 10:46 AM
Does nobody have a any ideas?
Feb 9, 2009 at 1:53 PM
Hi strauchdieb,

I run into the very same problem and I have posted a thread on it.
Let's pray together for an answer.
Feb 9, 2009 at 1:59 PM
I fact, the answer is here:


Feb 9, 2009 at 3:03 PM
Edited Feb 9, 2009 at 3:04 PM
Hi Roubachof

Thanks for your answer.
It seems that we have to live with the RibbonComboBoxItem for now. I hope they'll release a fix soon.