2017-07-17 56 views
1

我正在创建一个UWP应用程序(C#.NET),其中有文本框。我想实现一个快捷方式(Ctrl + F)来搜索文本框中的文本。我知道如何找到文本,但我不知道如何实现快捷方式。UWP 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 +ž快捷键(撤销)?

+0

根据[这个答案](https://stackoverflow.com/a/32782168/6741868)你可以尝试使用'Window.Current.CoreWindow.GetKeyState(VirtualKey.Control)'。 –

回答

4

您应该使用这里描述的“加速器”和“访问键”: 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