WPF MVVM ComboBox(in DataGrid)触发事件SelectionChanged, 通知到ViewModel.

2021-03-20 11:27

阅读:462

标签:binding   gen   end   foreach   round   object   lte   cas   relative   

1.View

  

    
      
        
          
            
          

        

      
    

  

 

2.View.cs

private void DataGrid_AutoGeneratedColumns(object sender, EventArgs e)
{

  foreach (var name in names)
  {

    switch (dataGridHeader)
    {
      case "COMPUTERULE":
        dataGridTemplateColumn = new DataGridTemplateColumn { Header = name };
        dt = dataGrid.Resources["ComputeRuleColumnTemplate"] as DataTemplate;
        dataGridTemplateColumn.CellTemplate = dt;
        dg.Columns.Add(dataGridTemplateColumn);
      break;

    }

  }

}

 

3.ViewModel

public ICommand ComboBoxComputeRuleSelectionChangedCommand { get; private set; }

public void InitialCommand()
{

  ComboBoxComputeRuleSelectionChangedCommand = new DelegateCommand(OnComboBoxComputeRuleSelectionChangedCommand);
}

private void OnComboBoxComputeRuleSelectionChangedCommand()
{
  UpdateResultObrclnByComboBoxComputeRuleSelectionChanged();
}

WPF MVVM ComboBox(in DataGrid)触发事件SelectionChanged, 通知到ViewModel.

标签:binding   gen   end   foreach   round   object   lte   cas   relative   

原文地址:https://www.cnblogs.com/akiva/p/12303478.html


评论


亲,登录后才可以留言!