如何禁用某些按钮的加速键

Ger*_*rry 4 wpf xaml accelerator button

我将 Button 的 .Content 值设置为包含下划线的字符串;第一个下划线被解释为加速键。

在不更改底层字符串(通过用 __ 替换所有 _ )的情况下,有没有办法禁用非菜单按钮的加速器?

Mat*_*ton 5

一种简单的方法是将字符串嵌入到 TextBlock 中(它没有访问键的概念),并将其用作按钮的内容而不是原始字符串:

<Button><TextBlock Text="{Binding TextWithUnderscore}" /></Button>
Run Code Online (Sandbox Code Playgroud)