[英]WPF Add KeyBinding events with umlaut characters in XAML
Can anyone tell me why keybinding events do not work with umlaut characters like this? 谁能告诉我为什么键绑定事件对像这样的变音符号不起作用?
Trying in xaml 在XAML中尝试
<Grid.InputBindings>
<KeyBinding Key="Ü" ... />
</Grid.InputBindings>
Will throw error: 会抛出错误:
Cannot convert string value 'Ü' to type
System.Windows.Input.Key
无法将字符串值“Ü”转换为
System.Windows.Input.Key
类型
I've made a small test program to find out which Key
is what. 我编写了一个小型测试程序,以找出哪个
Key
是什么。 Make new WPF project and add to main window cs-file: 制作新的WPF项目并添加到主窗口cs文件中:
public MainWindow()
{
InitializeComponent();
var skip = new[] { Key.None, Key.DeadCharProcessed };
foreach (Key value in Enum.GetValues(typeof(Key)))
if (!skip.Contains(value))
InputBindings.Add(new KeyBinding { Command = new MyCommand(value.ToString()), Key = value });
}
public class MyCommand : ICommand
{
public event EventHandler CanExecuteChanged;
public string Text { get; }
public MyCommand(string text) { Text = text; }
public bool CanExecute(object parameter) => true;
public void Execute(object parameter) => MessageBox.Show(Text);
}
To save you time: 为节省时间:
Ü = Key.Oem1
Ö = Key.Oem3
Ä = Key.OemQuotes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.