[英]Extended WPF Toolkit DataGridControl with NavigationCommands.Refresh
In my WPF application, I want to handle user F5 strokes as refresh. 在我的WPF应用程序中,我希望将用户F5笔划作为刷新处理。 In order to archieve that, I decided to utilize the
NavigationCommands.Refresh
command. 为了解决这个问题,我决定使用
NavigationCommands.Refresh
命令。
Inside the UI, I utilize the DataGridControl
from Extended WPF Toolkit . 在UI内部,我利用Extended WPF Toolkit中的
DataGridControl
。 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: 复制:
DataGridControl
area, press F5 - handler is not executed DataGridControl
区域,按F5键-未执行处理程序 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
? 所以问题是,当焦点位于
DataGridControl
内时,当用户按F5键时,如何确保执行刷新处理程序?
Ok, I finally stumbled upon the solution. 好的,我终于偶然发现了解决方案。
https://xceed.com/forums/topic/what-is-the-function-key-F5-in-datagrid-for/ 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. 将
DataGridControl.IsRefreshCommandEnabled
属性设置为False
阻止datagridcontrol将F5键用于其内部逻辑。 Then the handler is called as expected. 然后按预期方式调用该处理程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.