Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1336
Single GotFocus/LostFocus events for XamDataGrid?
posted

Hi,

I need to be able to detect when a XamDataGrid gets and loses focus.  There could be multiple grids displayed and I would like to hook up some commands when a grid receives focus and un-hook the commands when the grid looses focus - so the commands apply to the currently active grid.

I would expect that the grid raises a GotFocus event when it receives focus, and a LostFocus event when it loses focus, however, there are several items within the template of the grid that are Focusable.  Every time I simply change the selection within the grid, I get 2 LostFocus events followed by 1 GotFocus.

I tried specifying a style for the DataRecordPresenter (the main element causing the extra events to be fired) and setting the "Focusable" property to "False".  This appears to have the desired effect - I am only getting one GotFocus event when the focus moves to the grid - I can navigate within the grid without subsequent focus events firing, then only when I navigate to a different element within the window do I get the LostFocus firing :-)

Is this ok?  Could it have any undesired side-effects, or is this an acceptable thing to do?   ...or am I missing the point and should be tackling this some other way?

Any guidance would be much appreciated,

Dave