【问题标题】:WPF ContextMenu to access row selectedWPF ContextMenu 访问选定的行
【发布时间】:2012-05-22 13:21:26
【问题描述】:

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

【问题讨论】:

    标签: wpf contextmenu


    【解决方案1】:

    这将使用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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-09
      • 1970-01-01
      • 1970-01-01
      • 2017-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多