GotFocus and LostFocus events on DataGrid cell?

May 15, 2009 at 9:58 PM
Edited May 15, 2009 at 10:05 PM

Hi, Is there a way (other than using  this code to hook it up for ALL classes

EventManager.RegisterClassHandler(typeof(DataGridCell),  DataGridCell.GotFocusEvent, new RoutedEventHandler (GotFocusHandler));<font size="2" color="#008000"><font size="2" color="#008000">

 

</font></font><font size="2" color="#008000">

 

</font>

   ) to hook up events when a cell is clicked on, and when the user leaves a DataGrid cell?

I need to handle something in an event when the cell is clicked on (GotFocus?) on a datagrid cell, as well as when the user has completed their typing / changes in the cell, and are leaving the cell and moving onto the next field.

 

Also, one other requirement is that I need to be able to add and remove the event in the codebehind, not in the XAML (or at least I need to be able to remove the event handler in the codebehind...)

How can I do this?

Thanks,
Chris