I’m trying to bind IsChecked to the Selected DependancyProperty on the object I’m displaying, this code appears to work, but submenus don’t show up if I use it. Is this the right way to go about it, and how do I fix the problem?
<MenuItem Header='Window' Name='windowMenu' ItemsSource='{Binding}'> <MenuItem.ItemContainerStyle> <Style> <Setter Property='MenuItem.IsChecked' Value='{Binding Path=Selected}' /> <Setter Property='MenuItem.IsCheckable' Value='true' /> </Style> </MenuItem.ItemContainerStyle> </MenuItem>
A quick test reveals that if a MenuItem’s IsCheckable property is set to True, it will not display its child items.
In the example above, Options will have no children displaying.
Edit: The reason this is the case is that from a user experience standpoint, this is not a case that really makes sense. The only case I can think of is checking an item which checks all of its subitems, but I’d suppose you’d be better off using checkboxes for that.
Redefining the ControlTemplate is certainly an option. Blend can usually tell you what the default control template it and you can go from there.