Resolved How to bind Menu items with observableCollection in xaml and wpf?

destro

Well-known member
Joined
Mar 28, 2020
Messages
46
Programming Experience
1-3
I can assign them using <Menuitem Header> but how to view all the items present in the Observable collection in a view model?

C#:
 <Menu Grid.Row="1" Grid.Column="1" Width="100" VerticalAlignment="Center" Background="Gray">
            <MenuItem Header="Item Collection">
                <MenuItem Header="Item 1"></MenuItem>
                <MenuItem Header="Item 2"></MenuItem>
                <MenuItem Header="Sub Items">
                    <MenuItem Header="SubItem 1"></MenuItem>
                    <MenuItem Header="SubItem 2"></MenuItem>
                </MenuItem>
            </MenuItem>
        </Menu>

View Model contains a simple int type observable collection.
 
See:
 
Sorry, my bad. I thought you were trying to see how to bind the command. It looks like what you wanted to do is to populate the menu itself.

A Menu is a ItemsControl. Presumably you would populate it the same way you would populate a [il]ListBox[/icode], Combobox, DataGrid, etc., by binding to the Items property.
 
A Menu is a ItemsControl. Presumably you would populate it the same way you would populate a [il]ListBox[/icode], Combobox, DataGrid, etc., by binding to the Items property.
It Worked. The problem was I was setting something wrong with menu item template. I removed that and it works by simply setting the item source.
 
Back
Top Bottom