【问题标题】:UWP Ctrl+F implementationUWP Ctrl+F 实现
【发布时间】:2017-12-21 14:24:40
【问题描述】:

我正在创建一个带有文本框的 UWP 应用 (C# .NET)。我想实现一个快捷方式 (Ctrl+F) 来搜索文本框中的文本。我知道如何查找文本,但我不知道如何实现快捷方式。

我发现了这个:

if ((e.Control && e.KeyCode == Keys.F) || (e.Control && e.KeyCode == Keys.S)) 
{
    //do something
}

...但它不适用于 UWP。我试过了(textarea 是文本框的名称):

private void textarea_KeyDown(object sender, KeyRoutedEventArgs e)
{
    if ((e.Key == Windows.System.VirtualKey.Control) && (e.Key == Windows.System.VirtualKey.F))
    {
        flayoutFind.ShowAt(appBarButtonFind as FrameworkElement);
    }
}

但它也不起作用。我该怎么做?

对于未来,有什么办法,如何覆盖文本框的默认功能和快捷方式Ctrl+Z(撤消)?

【问题讨论】:

  • 基于this answer,您可以尝试使用Window.Current.CoreWindow.GetKeyState(VirtualKey.Control)

标签: c# .net uwp find shortcut


【解决方案1】:

您应该使用此处所述的“加速器”和“访问密钥”: https://docs.microsoft.com/en-us/windows/uwp/input-and-devices/keyboard-interactions

基本上,您必须注册参加活动

Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated;

private void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args)
    {
         //Implementation
    }

您可以在此处详细查看示例:https://github.com/Microsoft/DesktopBridgeToUWP-Samples/blob/master/Samples/SQLServer/BuildDemo/MainPage.xaml.cs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    • 2013-06-11
    • 2014-02-11
    • 1970-01-01
    相关资源
    最近更新 更多