WPF DataGrid - Event for New Rows?

前端 未结 7 1921
梦谈多话
梦谈多话 2020-12-06 17:13

I\'m using the WPF DataGrid (.Net 3.5 SP 1 version from the Toolkit)

What event can I subscribe to, to detect when a new row is added?

7条回答
  •  抹茶落季
    2020-12-06 17:56

    In you XAML, include the following code in your Window tag:

    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:cmd="http://www.galasoft.ch/mvvmlight"
    

    Next, inside you DataGrid element, add the following trigger:

    
    
      
            
                   
                                     
       
    
    
    

    Next, in you View Model, add a command for handling the event :

    public RelayCommand LoadRowHandler{ get; private set; }
    

    Inside constructor, initialize the command:

    LoadRowHandler = new RelayCommand(LoadingRowHandlerMethod);
    

    Next, create a method where you want to put the logic:

    private void LoadingRowHandlerMethod(DataGridRowEventArgs e)
    {
      //....
      //....
    }
    

    That's all. Now whenever a new row is added to your DataGrid, the LoadingRowHandlerMethod will get executed.

    Hope it helps.

提交回复
热议问题