gpt4 book ai didi

c# - WPF 子菜单项面板

转载 作者:行者123 更新时间:2023-12-03 10:57:59 25 4
gpt4 key购买 nike

我想在多个列中显示菜单项..

我想使用 WrapPanels 用于菜单

下面的代码适用于第一级,但是当打开子菜单或子菜单的子菜单时,它显示为普通列表。

可以做些什么来覆盖默认行为。

注意:我正在使用 Itemssource绑定(bind)菜单项(我自己的类的对象),所以我不能给嵌套项样式。

<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>

最佳答案

您可以绑定(bind)到任何级别

          <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>

关于c# - WPF 子菜单项面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36300982/

25 4 0