Reputation: 7248
I want to show the menu items in multiple Columns..
I want to use WrapPanels for menus
below code works well for first level, but when opening sub menus or sub menus of sub menus , its shows as ordinary list.
What can be done to override the default behavior.
note: I am using Itemssource
to bind menu items (Objects of my own Class), so i can't give nested Item Styles.
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
....
<Setter Property="ItemsSource" Value="{Binding Children}"/>
....
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<WrapPanel MaxHeight="300" Orientation="Vertical"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
....
</Style>
Upvotes: 0
Views: 977
Reputation: 18578
You can bind to any level
<Style TargetType="MenuItem">
<Setter Property="ItemsSource" Value="{Binding Children}"/>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<WrapPanel MaxHeight="300" Orientation="Vertical"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="MenuItem">
<Setter Property="ItemsSource" Value="{Binding Children}"/>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<WrapPanel MaxHeight="300" Orientation="Vertical"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="MenuItem">
<Setter Property="ItemsSource" Value="{Binding Children}"/>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<WrapPanel MaxHeight="300" Orientation="Vertical"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
</Style>
Upvotes: 3