Here's the scenario, I am using the WPF Ribbon control (release version). I have a RibbonSplitButton and I want it to present a list of checkable RibbonMenuItems based on an obserable collection of object that is populated at runtime. My first inclination is to set the ItemsSource property of the RibbonSplitButton to my observable collection, then create a datatemplate specified as the ItemsTemplate property of the RibbonSplitButton which contains the RibbonMenuItem. This XAML would look like this:
<ribbon:RibbonSplitButton ItemsSource="{MySource}">
<ribbon:RibbonSplitButton.ItemTemplate>
<DataTemplate>
<ribbon:RibbonMenuItem Header="{Binding MyHeader}" IsCheckable="True" IsChecked="{Binding MyIsChecked}"></< font>ribbon:RibbonMenuItem>
</DataTemplate>
</ribbon:RibbonSplitButton.ItemTemplate>
</ribbon:RibbonSplitButton>
What this actually yields though is a RibbonMenuItem rendered inside of another RibbonMenuItem. Quite ugly. The reason for this is that the default object type that is used to present an item in a RibbonSplitButton's dropdown IS a RibbonMenuItem. So this datatemplate puts a RibbonMenuItem inside of another. Once I realized this I figured out that using the ItemContainerStyle could get me the result I wanted. The ItemContainerStyle styles the control that is being used to render the item. Since it is a RibbonMenuItem already (which happens to be the object type I wanted to use anyway) we can use Setters bound to our object to acheive our goal. Here's the proper XAML:
<ribbon:RibbonSplitButton x:Key="Hello" ItemsSource="{MySource}">
<ribbon:RibbonSplitButton.ItemContainerStyle>
<Style TargetType="{x:Type ribbon:RibbonMenuItem}">
<Setter Property="Header" Value="{Binding Name}"/>
<Setter Property="IsCheckable" Value="True"/>
<Setter Property="IsChecked" Value="{Binding IsChecked}"/>
</ Style>
</ribbon:RibbonSplitButton.ItemContainerStyle>
</ribbon:RibbonSplitButton>
I hope this helps someone else out there and I hope it makes sense!
Sean