lundi 29 juin 2015

Command doesn't work on top level MenuItem in MVVM

It works fine if the MenuItem doesn't have a sub MenuItem, like this:

<MenuItem Header = "Open" Command="{Binding OpenCommand}"/>

but, when I add a sub MenuItem to it, the Command doesn't work:

<MenuItem Header = "Open" Command="{Binding OpenCommand}">
    <MenuItem />
</MenuItem>

I know I can add the Command to the header as a remedy:

<MenuItem>
    <MenuItem.Header>
        <Button Content = "Open" Command="{Binding OpenCommand}"/>
    </MenuItem.Header>
    <MenuItem/>
</MenuItem>

but is there a elegant way to fix it? any help will be appreciate.

Aucun commentaire:

Enregistrer un commentaire