大家晚上好
我试图根据所述ListView的列值更改WPF ListView ContextMenu标头。具体来说,当列绑定到STATUS =“ Y”(保持)或“ N”(不保持)的值时,我想将其从Enable更改为Disable(反之亦然)。我尝试了以下方法:
<ContextMenu.Resources>
<Style TargetType="{x:Type MenuItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding STATUS}" Value="Y">
<Setter Property="Header" Value="Enable" />
</DataTrigger>
<DataTrigger Binding="{Binding STATUS}" Value="N">
<Setter Property="Header" Value="Disable" />
</DataTrigger>
</Style.Triggers>
</Style>
</ContextMenu.Resources>
第二次尝试:
<ListView.ContextMenu>
<ContextMenu x:Name="cmlv">
<MenuItem x:Name="cmdisableenable">
<MenuItem.Resources>
<Style TargetType="{x:Type MenuItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding STATUS}" Value="Y">
<Setter Property="Header" Value="Enable" />
</DataTrigger>
<DataTrigger Binding="{Binding STATUS}" Value="N">
<Setter Property="Header" Value="Disable" />
</DataTrigger>
</Style.Triggers>
</Style>
</MenuItem.Resources>
</MenuItem>
</ContextMenu>
</ListView.ContextMenu>
答案 0 :(得分:0)
<MenuItem>
<MenuItem.Resources>
<Style TargetType="{x:Type MenuItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding STATUS}" Value="Y">
<Setter Property="Header" Value="Enable" />
</DataTrigger>
<DataTrigger Binding="{Binding STATUS}" Value="N">
<Setter Property="Header" Value="Disable" />
</DataTrigger>
</Style.Triggers>
</Style>
</MenuItem.Resources>
</MenuItem>
您在MenuItem上应用了样式,因此取决于状态,标题将为“禁用”或“启用”,并确保您不为标题分配任何值