Getting WPF Data Grid Context Menu Click Row

后端 未结 6 654
无人共我
无人共我 2021-01-31 10:30

I have a WPF DataGrid



    

        
6条回答
  •  忘了有多久
    2021-01-31 11:01

    To expand morincer's point above with an example, I ended up with a simpler approach...

     private void MenuItem_OnClickRemoveSource(object sender, RoutedEventArgs e)
     {
         if (SourceDataGrid.SelectedItem == null) return;  //safety first
    
         _importViewModel.SourceList.Remove((SourceFileInfo)SourceDataGrid.SelectedItem);
     }
    

    In my case, the

    _importViewModel.SourceList 
    

    is the ObservableCollection the rows are bound to. So per best practices, I simple remove the selected item from the collection and the binding takes care of the UI.

提交回复
热议问题