views:

277

answers:

1

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: 

A quick test reveals that if a MenuItem's IsCheckable property is set to True, it will not display its child items.

    <Menu>
        <MenuItem Header="File">
            <MenuItem Header="Exit" />
        </MenuItem>
        <MenuItem Header="Tools">
            <MenuItem Header="Options" IsCheckable="True">
                <MenuItem Header="one" IsCheckable="True" />
                <MenuItem Header="two" IsCheckable="True" />
            </MenuItem>
        </MenuItem>
    </Menu>

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.

siz
What's a good workaround for that problem then? I assume I can redefine the control template, but I'm not sure what the default template is and I don't want to lose any functionality of it.
Eric
If you have Blend, you can Edit a copy of the existing control template and it will spit out the complete default template definition. Otherwise you'll have to poke around the WPF libraries to find it.
KP Adrian