gpt4 book ai didi

c# - InputBindings 的 WinRT 等价物是什么?

转载 作者:太空狗 更新时间:2023-10-29 20:05:35 24 4
gpt4 key购买 nike

WPF 允许我使用 InputBindings 属性轻松地将窗口级别的键盘快捷方式绑定(bind)到方法。这在 WinRT 中相当于什么?在 WinRT 中将键盘快捷键绑定(bind)到方法的正确方法是什么?

最佳答案

描述了键盘快捷键 here .我想你想要 access keysaccelerator keys .

An access key is a shortcut to a piece of UI in your app. Access keys consist of the Alt key plus a letter key.

An accelerator key is a shortcut to an app command. Your app may or may not have UI that corresponds exactly to the command. Accelerator keys consist of the Ctrl key plus a letter key.

The following example demonstrates the accessible implementation of shortcut keys for media play, pause, and stop buttons:

<MediaElement x:Name="Movie" Source="sample.wmv"
AutoPlay="False" Width="320" Height="240"/>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">

<Button x:Name="Play" Margin="1,2"
ToolTipService.ToolTip="shortcut key: Ctrl+P"
AutomationProperties.AccessKey="Control P">
<TextBlock><Underline>P</Underline>lay</TextBlock>
</Button>

<Button x:Name="Pause" Margin="1,2"
ToolTipService.ToolTip="shortcut key: Ctrl+A"
AutomationProperties.AccessKey="Control A">
<TextBlock>P<Underline>a</Underline>use</TextBlock>
</Button>

<Button x:Name="Stop" Margin="1,2"
ToolTipService.ToolTip="shortcut key: Ctrl+S"
AutomationProperties.AccessKey="Control S">
<TextBlock><Underline>S</Underline>top</TextBlock>
</Button>

</StackPanel>

<object AutomationProperties.AcceleratorKey="ALT+F" />

Important: Setting AutomationProperties.AcceleratorKey or AutomationProperties.AccessKey doesn't enable keyboard functionality. It only reports to the UI Automation framework what keys should be used, so that such information can be passed on to users via assistive technologies. The implementation for key handling still needs to be done in code, not XAML. You will still need to attach handlers for KeyDown or KeyUp events on the relevant control in order to actually implement the keyboard shortcut behavior in your app. Also, the underline text decoration for an access key is not provided automatically. You must explicitly underline the text for the specific key in your mnemonic as inline Underline formatting if you wish to show underlined text in the UI.

有关代码方面的实现细节,请参阅@Magiel 的回答。

关于c# - InputBindings 的 WinRT 等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11554715/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com