C# 根据listview项禁用/启用上下文菜单项
我有一个C# 根据listview项禁用/启用上下文菜单项,c#,.net,wpf,xaml,contextmenu,C#,.net,Wpf,Xaml,Contextmenu,我有一个UserControl,里面有一个ListView。 此外,我还有一个类listViewItems.cs,它的DisplayMemberBinding绑定到listView中的GridView 每个ListView项都有一个上下文菜单。 现在,我尝试启用/禁用上下文菜单项,具体取决于类ListViewItems中的值是否为null 我已尝试将IsEnabled属性绑定到类ListViewItems.cs中的布尔值ShowResItemEn,但它不起作用 DataOutput.xaml &
UserControl
,里面有一个ListView
。
此外,我还有一个类listViewItems.cs,它的DisplayMemberBinding绑定到listView
中的GridView
每个ListView项都有一个上下文菜单。
现在,我尝试启用/禁用上下文菜单项,具体取决于类ListViewItems中的值是否为null
我已尝试将IsEnabled
属性绑定到类ListViewItems.cs中的布尔值ShowResItemEn
,但它不起作用
DataOutput.xaml
<ListView.Resources>
<ContextMenu x:Name="cmListView" x:Key="ItemContextMenu" DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}">
<MenuItem x:Name="itmRes"
Header="Reservierungen anzeigen"
IsEnabled="{Binding PlacementTarget.SelectedItem.ShowResItemEn, RelativeSource={RelativeSource FindAncestor,AncestorType=ContextMenu}}"
Command="{Binding ShowResItemCmd}"
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}" >
</MenuItem>
</ContextMenu>
</ListView.Resources>
好的,现在可以了。我把字体调错了
IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}},Path=SelectedItem.ShowBesItemEn}"
您的关联菜单在项目中还是在列表视图中?我编辑了我的问题,其定义为listview资源您包含了太多的代码和不够的代码。请提供清楚说明您的问题的信息。请详细解释该代码现在的功能以及与您希望它的功能有何不同。与论坛网站不同,我们不使用“感谢”或“感谢任何帮助”或签名。请看“.顺便说一句,这是“提前感谢”,不是“提前感谢”。好的,我现在编辑了我的问题。希望对你有所帮助
IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}},Path=SelectedItem.ShowBesItemEn}"