@@ -22,23 +22,24 @@ public object Content
2222 set => SetValue ( ContentProperty , value ) ;
2323 }
2424
25- public static readonly DependencyProperty ContentProperty = DependencyProperty . Register ( "Content" , typeof ( object ) , typeof ( KeyVisual ) , new PropertyMetadata ( default ( string ) , OnContentChanged ) ) ;
25+ public static readonly DependencyProperty ContentProperty =
26+ DependencyProperty . Register ( nameof ( Content ) , typeof ( object ) , typeof ( KeyVisual ) , new PropertyMetadata ( null , OnContentChanged ) ) ;
2627
2728 public VisualType VisualType
2829 {
2930 get => ( VisualType ) GetValue ( VisualTypeProperty ) ;
3031 set => SetValue ( VisualTypeProperty , value ) ;
3132 }
3233
33- public static readonly DependencyProperty VisualTypeProperty = DependencyProperty . Register ( " VisualType" , typeof ( VisualType ) , typeof ( KeyVisual ) , new PropertyMetadata ( default ( VisualType ) , OnSizeChanged ) ) ;
34+ public static readonly DependencyProperty VisualTypeProperty = DependencyProperty . Register ( nameof ( VisualType ) , typeof ( VisualType ) , typeof ( KeyVisual ) , new PropertyMetadata ( default ( VisualType ) , OnSizeChanged ) ) ;
3435
3536 public bool IsError
3637 {
3738 get => ( bool ) GetValue ( IsErrorProperty ) ;
3839 set => SetValue ( IsErrorProperty , value ) ;
3940 }
4041
41- public static readonly DependencyProperty IsErrorProperty = DependencyProperty . Register ( " IsError" , typeof ( bool ) , typeof ( KeyVisual ) , new PropertyMetadata ( false , OnIsErrorChanged ) ) ;
42+ public static readonly DependencyProperty IsErrorProperty = DependencyProperty . Register ( nameof ( IsError ) , typeof ( bool ) , typeof ( KeyVisual ) , new PropertyMetadata ( false , OnIsErrorChanged ) ) ;
4243
4344 public KeyVisual ( )
4445 {
@@ -82,13 +83,21 @@ private void Update()
8283
8384 if ( _keyVisual . Content != null )
8485 {
85- object content = _keyVisual . Content ;
86- VirtualKey key = content switch
86+ VirtualKey key = VirtualKey . None ;
87+
88+ var content = _keyVisual . Content ;
89+ string keyName = null ;
90+
91+ if ( content is string strContent )
8792 {
88- string str => GetVirtualKeyFromString ( str ) ,
89- VirtualKey vk => vk ,
90- _ => ( VirtualKey ) ( int ) content
91- } ;
93+ key = GetVirtualKeyFromString ( strContent ) ;
94+ keyName = strContent ;
95+ }
96+ else if ( content is KeyVisualInfo keyVisualInfo )
97+ {
98+ key = ( VirtualKey ) keyVisualInfo . Key ;
99+ keyName = keyVisualInfo . KeyName ;
100+ }
92101
93102 if ( TryGetIconForKey ( ( int ) key , out object iconContent ) )
94103 {
@@ -98,7 +107,7 @@ private void Update()
98107 else
99108 {
100109 _keyVisual . Style = GetStyleSize ( "TextKeyVisualStyle" ) ;
101- _keyVisual . _keyPresenter . Content = content . ToString ( ) ;
110+ _keyVisual . _keyPresenter . Content = keyName ;
102111 }
103112 }
104113 }
0 commit comments