【发布时间】:2012-05-22 13:21:26
【问题描述】:
我有一个 WPF 应用程序,其中有一个 ListView 和一个 GridView。当您右键单击网格中的项目时,它有一个ContextMenu。我想知道如何访问从ContextMenu 中选择的行并以编程方式访问该行。我的目标是删除该行数据。谢谢!
【问题讨论】:
标签: wpf contextmenu
我有一个 WPF 应用程序,其中有一个 ListView 和一个 GridView。当您右键单击网格中的项目时,它有一个ContextMenu。我想知道如何访问从ContextMenu 中选择的行并以编程方式访问该行。我的目标是删除该行数据。谢谢!
【问题讨论】:
标签: wpf contextmenu
这将使用WPF command bindings...
<ListView>
<!-- .... -->
<ListView.ContextMenu>
<ContextMenu>
<MenuItem Header="Remove Item" Command="{Binding RemoveItem}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}},Path=PlacementTarget.SelectedItem}" Icon="{StaticResource deleteIcon}"/>
</DataGrid.ContextMenu>
</ListView.ContextMenu>
</ListView>
要创建自定义命令绑定,请参阅this SO post。
【讨论】: