UWP Ctrl+F 实现
UWP Ctrl+F implementation
我正在创建一个有文本框的 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(撤消) ?
您应该按照此处所述使用 "Accelerators" 和 "Access keys":
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
我正在创建一个有文本框的 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(撤消) ?
您应该按照此处所述使用 "Accelerators" 和 "Access keys": 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