WPF Datagrid Double Click Cell MVVM Design

后端 未结 4 1866
太阳男子
太阳男子 2021-01-03 14:04

I have a WPF application that contains a datagrid. It is bound to my List object \"Orders\" shown below.

public class OrderBlock
{
  public Settings setting;         


        
4条回答
  •  花落未央
    2021-01-03 14:32

    I'v used the MouseDoubleClick:

        private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs eventArgs)
        {
            if (sender == null) return;
            if (eventArgs.ButtonState != MouseButtonState.Pressed) return; //only react on pressed
    
            var dataGrid = sender as DataGrid;
            if (dataGrid == null || dataGrid.SelectedItems == null) return;
    
            if (dataGrid.SelectedItems.Count == 1)
            {
                var simplePension = dataGrid.SelectedItem as ISimplePension;
                if (simplePension != null)
                {
                    DataFetcherHolder.DataFetcher.SelectPension(simplePension);
                    Execute(EditSelectedPensionFunction);
                }
            }
        }
    

    When you double-click a data grid, the row is also selected, so I simply find the selected item and use it.

提交回复
热议问题