[英]How to disable context menu on Listview header
I have a context menu which is displayed when I right clicked on the items, on header and on empty space of the listview. 我有一个上下文菜单,当我右键单击项目,标题和列表视图的空白区域时会显示该菜单。 How can I display the context menu on the empty space of the listview but not on the header.
如何在上下文列表的空白处而不是在标题上显示上下文菜单。
<ListView.View>
<GridView AllowsColumnReorder="True"
<GridViewColumn Width="100" Header="Company" DisplayMemberBinding="{Binding Company}" />
<GridViewColumn Width="100" Header="Depatment" DisplayMemberBinding="{Binding Department}" />
<GridViewColumn Width="100" Header="Office" DisplayMemberBinding="{Binding Office}" />
</GridView>
</ListView.View>
<ListView.ContextMenu>
<ContextMenu>
<MenuItem Header="Add" Command="{Binding Add}"></MenuItem>
</ContextMenu>
</ListView.ContextMenu>
If you set the value of columnheader context menu to null, ie. 如果将columnheader上下文菜单的值设置为null,即。
ColumnHeaderContextMenu="{x:Null}"
it's not gonna work ... But you can hack it like this ColumnHeaderContextMenu="{x:Null}"
它不起作用...但是您可以像这样破解它
<GridView.ColumnHeaderContextMenu>
<ContextMenu>
<ContextMenu.Template>
<ControlTemplate>
<Border BorderBrush="Transparent"
Background="Transparent" />
</ControlTemplate>
</ContextMenu.Template>
</ContextMenu>
</GridView.ColumnHeaderContextMenu>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.