【问题标题】:Telerik UI For UWP DataGrid Enter KeyTelerik UI For UWP DataGrid 输入键
【发布时间】:2019-04-10 13:49:24
【问题描述】:

我正在为 UWP 使用 Telerik Datagrid。我正在使用PreviewKeyDown 来捕获 Enter 键。当按下 Enter 键时,我想将焦点设置到另一个控件。

private async void bookingGrid_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
{
     if (e.Key==Windows.System.VirtualKey.Enter)
     {
        //the methodfires but focus does not shift to the required control
        await FocusManager.TryFocusAsync(anotherControl, FocusState.Keyboard);
        // this does not focus the other control??
     }
}

其他键工作正常,但 Enter 键不能。我试过了

    e.Handled = true;

    e.Handled = false;

【问题讨论】:

  • 你能试试KeyDownKeyUp 事件而不是PreviewKeyDown吗?

标签: uwp telerik-grid


【解决方案1】:

问题可能是您设置e.Handled = true 太晚了。

当到达await时,对于系统来说,事件处理程序的执行基本上停止了,所以如果你在await之后设置Handled,它就不会被系统拾取,它会继续执行KeyDown 这很可能会阻止将焦点设置到另一个控件并将其保留在 DataGrid 中。

你需要在焦点改变之前设置Handled

private async void bookingGrid_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
{
     if (e.Key==Windows.System.VirtualKey.Enter)
     {
        e.Handled = true;
        await FocusManager.TryFocusAsync(anotherControl, FocusState.Keyboard);
     }
}

另一种解决方案是让控制过程按下 Enter 键并在 KeyUp 事件处理程序中设置焦点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多