这些角色的键码是什么? - WPF

问题描述 投票:0回答:1

我正在开发基于Windows Presentation Foundation(WPF)的代码编辑器。当用户添加一个打开的brakcet时,我想自动添加关闭括号。但在System.Windows.Input.Key,我找不到括号的键码。我还需要在代码部分中提到下面提到的一些字符代码。

//  Brackets, square brackets and curly brackets "("  ")" "[" "]" "{" "}" 
//  Lower/Greater: "<" ">"
//  Equal, quote and single quote " ' =

private void htmlcode_KeyDown(object sender, KeyEventArgs e)
{
   if(e.Key=<the keycode that I need>)
   {
      htmlcode.Text=htmlcode.Text+"<close variant of key>";
   } 
} 

我需要System.Windows.Input.Key枚举中这些字符的名称。

c# wpf xaml event-handling enumeration
1个回答
1
投票

System.Windows.Input.Key枚举没有这些字符的值。

但是你可以处理PreviewTextInput事件而不是KeyDown

private void htmlcode_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
    switch (e.Text)
    {
        case "{":
            // add "}"
            break;
        // etc
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.