0

This is XAML codes.

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
    <Menu x:Name="Menu1">
        <MenuItem x:Name="MenuItem1" Height="40" Header="File">
            <MenuItem x:Name="MenuItem11" Header="Help"/>
            <MenuItem x:Name="MenuItem12" Header="About"/>
            <MenuItem x:Name="MenuItem13" Header="Exit"/>
        </MenuItem>
    </Menu>
</Grid>
</Window>

How to expand sub menus from code behind?

Question picture: https://prnt.sc/img9p6

1 Answers1

0

You will need a MenuViewModel class that has a ObservalbleCollection of SubMenuViewModel(s).

This class will need a property for the IsOpen for The Menu. https://msdn.microsoft.com/en-us/library/system.windows.controls.menuitem.issubmenuopen(v=vs.110).aspx

You should not create the MenuItems in WPF. But bind the Itemssource to thies collection.

You then bind the IsOpen from the MenuItem to the MenuItems in WPF (ItemsTemplate)

WPF - How can I create menu and submenus using binding

Marco
  • 984
  • 10
  • 18