-->

Custom Datagrid Event not firing

2019-08-02 14:00发布

问题:

I have 2 Extended Toolkit Datagrids in a window tied to 2 observable collections called Accounts and History. I would like to bind the cell edit ended event of the History DataGrid to a Command in my view model so that I can, among other things, update a value in the Accounts observable collection and have it reflected in the view.

To test that everything could work I used the below event:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="SelectionChanged">
       <cmd:EventToCommand Command="{Binding MyCmd}"/>
    </i:EventTrigger>
 </i:Interaction.Triggers>

This successfully triggered the command in the view model, made a static change in the observable collection and updated the view. So everything was good.

If I change the EventName to be CellEditEnded or so far every possible variation I can think of; nothing happens.

So, what event name should I use to capture the Cell Edit Ended event of the WPF Extended Toolkit DataGrid? Any help would be great, I have no idea where to go from here.

Edit:

I found this post that suggested using a separate class to raise the CellEditEnded event. But I can't figure out how I am supposed to raise the custom event. Can any one explain how this should be used? Using the CellEditEnded event in EventTrigger as per the post still doesn't work.

public class MyDataGridControl : DataGridControl
{
    public MyDataGridControl()
    {
        this.AddHandler( Cell.EditEndedEvent, new RoutedEventHandler( MyDataGridControl.OnCellEditEnded ) );
    }

    public event RoutedEventHandler CellEditEnded;

    private void RaiseCellEditEnded( RoutedEventArgs e )
    {
        var handler = this.CellEditEnded;
        if( handler == null )
            return;

       handler.Invoke( this, e );
   }

   private static void OnCellEditEnded( object sender, RoutedEventArgs e )
   {
       var dataGrid = ( MyDataGridControl )sender;
       Debug.Assert( dataGrid != null );

       dataGrid.RaiseCellEditEnded( e );
   }
}

Edit 2:

I have now discovered this site which seemed promising. I adapted the code into the below and the class above does execute but the CellEditEnded event still doesn't fire.

private void HistoryDataGrid_EditEnded(object sender, RoutedEventArgs e)
{
    MyDataGridControl mydatagridcontrol = new MyDataGridControl();
    mydatagridcontrol.CellEditEnded += new RoutedEventHandler(mydatagridcontrol_CellEditEnded);            
    mydatagridcontrol.RaiseEvent(e);
}
void mydatagridcontrol_CellEditEnded(object sender, RoutedEventArgs e)
{

}

I feel as though there should be something in the void mydatagridcontrol_CellEditEnded part but I don't know what I would put there.

Any help would really be appreciated.

Thanks!