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>
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.