[英]How to get the ListView Item that was right clicked before opening the context menu
I have a ListView with a ContextMenu attached to it. 我有一个附加了ContextMenu的ListView。 In the menu handler function I want to know, which item of the ListView was right clicked before the ContextMenu was shown. 在我想知道的菜单处理函数中,在显示ContextMenu之前右键单击ListView的项。
How can I do that ? 我怎样才能做到这一点 ?
I'm using WPF and C# 我正在使用WPF和C#
Add a handler to the ListView.ContextMenuOpening event: 将处理程序添加到ListView.ContextMenuOpening事件:
MainWindow.xaml: MainWindow.xaml:
<Grid>
<ListView x:Name="_myListView" />
</Grid>
MainWindow.xaml.cs code-behind: MainWindow.xaml.cs的代码隐藏:
this._myListView.ContextMenuOpening += this._myListView_ContextMenuOpening;
... ...
void _myListView_ContextMenuOpening(object sender, ContextMenuEventArgs e)
{
object selectedItem = this._myListView.SelectedItem;
// do something with selectedItem...
}
您可以向每个ListViewItem
添加MouseRightButtonUp
处理程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.