1

を含む WPF アプリケーションがありListViewますGridView。グリッド内のContextMenuアイテムを右クリックすると、 があります。ContextMenuから選択された行にアクセスし、プログラムでアクセスする方法を知りたいと思っていました。私の目標は、そのデータ行を削除することです。ありがとう!

4

1 に答える 1

3

これは、WPF コマンド バインディングを使用して機能します...

    <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>

カスタム コマンド バインディングを作成するには、この SO 投稿を参照してください。

于 2012-05-22T13:37:27.103 に答える