1
我有一个ListView
与GridView
在其中的WPF应用程序。当您右键单击网格中的项目时,它有一个ContextMenu
。我想知道如何访问从ContextMenu
中选择的行并以编程方式访问。我的目标是删除该行数据。谢谢!WPF ContextMenu访问所选行
我有一个ListView
与GridView
在其中的WPF应用程序。当您右键单击网格中的项目时,它有一个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。