我想在多列中显示菜单项。
我想用WrapPanels作为菜单
下面的代码适用于第一级,但当打开子菜单或子菜单时,其显示为普通列表。
可以做些什么来覆盖默认行为。
注意:我使用Itemssource来绑定菜单项(属于我自己类的对象),所以我不能给出嵌套的项目样式。
<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>发布于 2016-03-30 06:19:43
您可以绑定到任何级别。
<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>https://stackoverflow.com/questions/36300982
复制相似问题