I have a WPF DataGrid with some data bound to LINQ to SQL entity classes. One column is a clock showing a given flight's airborn time, which is calculated using logic in Flight's partial class. I have a timer calling datagrid.Items.Refresh every 2 seconds to update the clock.
The refresh works fine, but now I'm adding keyboard shortcuts. Navigating through cells with the keyboard arrows works fine with the timer off, but with the Refresh timer enabled, the focused cell (actually the entire datagrid) loses focus.
I need to either somehow maintain focus (preferred) or disable the timer whenever the DataGrid is focused. I can't even seem to get the latter to work. I've tried:
if (!dataGrid.IsFocused)
dataGrid.Items.Refresh();
and
if (!dataGrid.IsKeyboardFocused)
dataGrid.Items.Refresh();
for the timer, but these properties return false even when the datagrid is focused.
Any ideas?