From 20a0152b76c746346733a37fb0aeb6c8498eef7b Mon Sep 17 00:00:00 2001 From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> Date: Sat, 5 Aug 2023 00:40:30 +0800 Subject: [PATCH] fix: extract template property. --- .../Ursa.Demo/Pages/KeyGestureInputDemo.axaml | 6 ++-- .../Controls/KeyGestureInput.axaml | 11 ++++--- .../Themes/Shared/KeyGestureInput.axaml | 1 + src/Ursa/Controls/KeyGestureInput.cs | 30 +++++++------------ 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/demo/Ursa.Demo/Pages/KeyGestureInputDemo.axaml b/demo/Ursa.Demo/Pages/KeyGestureInputDemo.axaml index e828758..406c353 100644 --- a/demo/Ursa.Demo/Pages/KeyGestureInputDemo.axaml +++ b/demo/Ursa.Demo/Pages/KeyGestureInputDemo.axaml @@ -13,8 +13,8 @@ mc:Ignorable="d"> - + - + - + \ No newline at end of file diff --git a/src/Ursa.Themes.Semi/Controls/KeyGestureInput.axaml b/src/Ursa.Themes.Semi/Controls/KeyGestureInput.axaml index 56aab72..2bbbd31 100644 --- a/src/Ursa.Themes.Semi/Controls/KeyGestureInput.axaml +++ b/src/Ursa.Themes.Semi/Controls/KeyGestureInput.axaml @@ -3,22 +3,25 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:converters="using:Avalonia.Controls.Converters" xmlns:u="https://irihi.tech/ursa"> - + + + + 80 32 3 + 1 diff --git a/src/Ursa/Controls/KeyGestureInput.cs b/src/Ursa/Controls/KeyGestureInput.cs index 38dd28c..5c4e535 100644 --- a/src/Ursa/Controls/KeyGestureInput.cs +++ b/src/Ursa/Controls/KeyGestureInput.cs @@ -72,32 +72,24 @@ public class KeyGestureInput: TemplatedControl if (!ConsiderKeyModifiers) { - if(e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl || e.Key == Key.LeftAlt || e.Key == Key.RightAlt || e.Key == Key.LeftShift || e.Key == Key.RightShift || e.Key == Key.LWin || e.Key == Key.RWin) + if(e.Key is Key.LeftCtrl or Key.RightCtrl or Key.LeftAlt or Key.RightAlt or Key.LeftShift or Key.RightShift or Key.LWin or Key.RWin) { return; } Gesture = new KeyGesture(e.Key); } KeyGesture gesture; - if (e.KeyModifiers == KeyModifiers.Control && (e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl)) + switch (e.KeyModifiers) { - gesture = new KeyGesture(e.Key); - } - else if (e.KeyModifiers == KeyModifiers.Alt && (e.Key == Key.LeftAlt || e.Key == Key.RightAlt)) - { - gesture = new KeyGesture(e.Key); - } - else if (e.KeyModifiers == KeyModifiers.Shift && (e.Key == Key.LeftShift || e.Key == Key.RightShift)) - { - gesture = new KeyGesture(e.Key); - } - else if (e.KeyModifiers == KeyModifiers.Meta && (e.Key == Key.LWin || e.Key == Key.RWin)) - { - gesture = new KeyGesture(e.Key); - } - else - { - gesture = new KeyGesture(e.Key, e.KeyModifiers); + case KeyModifiers.Control when e.Key is Key.LeftCtrl or Key.RightCtrl: + case KeyModifiers.Alt when e.Key is Key.LeftAlt or Key.RightAlt: + case KeyModifiers.Shift when e.Key is Key.LeftShift or Key.RightShift: + case KeyModifiers.Meta when e.Key is Key.LWin or Key.RWin: + gesture = new KeyGesture(e.Key); + break; + default: + gesture = new KeyGesture(e.Key, e.KeyModifiers); + break; } Gesture = gesture; e.Handled = true;