I have a WPF application that has a ListView with a GridView in it. It has a ContextMenu when you right-click on the items in the grid. I was wondering how I can access the row that is selected from the ContextMenu and access that programatically. My goal is to delete that row of data. Thanks!
Asked
Active
Viewed 2,199 times
1
SliverNinja - MSFT
- 31,051
- 11
- 110
- 173
Badmiral
- 1,549
- 3
- 35
- 74
1 Answers
3
This will work using 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>
To create custom command bindings, see this SO post.
Community
- 1
- 1
SliverNinja - MSFT
- 31,051
- 11
- 110
- 173