Search code examples
c#wpfwpf-extended-toolkit

Extended WPF Toolkit DataGridControl with NavigationCommands.Refresh


In my WPF application, I want to handle user F5 strokes as refresh. In order to archieve that, I decided to utilize the NavigationCommands.Refresh command.

Inside the UI, I utilize the DataGridControl from Extended WPF Toolkit. The Problem: whenever the focus is within the data grid, the refresh command handler is not triggered.

This can be demonstrated with a very small sample:

<Window x:Class="WpfTests.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:xd="http://schemas.xceed.com/wpf/xaml/datagrid">
    <Window.CommandBindings>
        <CommandBinding Command="NavigationCommands.Refresh" Executed="CommandBinding_Executed" CanExecute="CommandBinding_CanExecute"/>
    </Window.CommandBindings>
    <StackPanel>
        <TextBox Text="Click me to get the focus out of DataGridControl"/>
        <xd:DataGridControl/>
    </StackPanel>
</Window>

Nothing fancy going on in code behind, I just use it to place breakpoints in the handler:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
    {
        e.Handled = true;
    }

    private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
    {
        e.CanExecute = true;
        e.Handled = true;
    }
}

Reproduce:

  • Start Application, press F5 - handler is executed
  • Click into the DataGridControl area, press F5 - handler is not executed
  • Click into the textbox, press F5 - handler is executed

So the question is, how can I ensure that my refresh handler is executed when the user presses F5 while focus is within the DataGridControl?


Solution

  • Ok, I finally stumbled upon the solution.

    https://xceed.com/forums/topic/what-is-the-function-key-F5-in-datagrid-for/

    Setting the DataGridControl.IsRefreshCommandEnabled property to False stops the datagridcontrol from consuming the F5 key for its own internal logic. Then the handler is called as expected.