【发布时间】:2015-06-12 08:07:56
【问题描述】:
我有一个UserControl,里面有一个ListView。
此外,我有一个类 listViewItems.cs,其 DisplayMemberBinding 与 listView 中的 GridView 绑定。
每个 ListView-Item 都有一个上下文菜单。
现在我正在尝试启用/禁用上下文菜单项,具体取决于 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>
类 ListViewItems.cs
public Boolean ShowResItemEn
{
get
{
return (auftrNr[0] == null) ? false : true;
}
}
【问题讨论】:
-
项目或列表视图中有上下文菜单吗?
-
我编辑了我的问题,它定义为 ListView 资源
-
您包含的代码太多,也不够。请提供a good, minimal, complete code example,清楚地说明您的问题。详细解释这段代码现在做了什么,以及它与你想要它做的有什么不同。
-
与论坛网站不同,我们不使用“谢谢”、“感谢任何帮助”或Stack Overflow 上的签名。请参阅“Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?。顺便说一句,这是“提前致谢”,而不是“在先致谢”。
-
好的,我现在编辑了我的问题。希望有帮助
标签: c# .net wpf xaml contextmenu