From db89faf2e169f1987b5acd083f2d4bb7db8a0374 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Sun, 8 Aug 2021 20:20:59 +0200 Subject: [PATCH] IsEnabled state support --- .../Microsoft.PowerToys.Settings.UI/App.xaml | 2 +- .../Controls/Setting/Setting.cs | 17 ++++++++++++++++- .../Controls/Setting/Setting.xaml | 5 ++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/App.xaml b/src/settings-ui/Microsoft.PowerToys.Settings.UI/App.xaml index 97e9d0d4b1..72d9ffa111 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/App.xaml +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/App.xaml @@ -20,7 +20,7 @@ - 6,16,20,16 + 6,16,16,16 16,0,0,0 diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/Setting/Setting.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/Setting/Setting.cs index ecfcda7f7d..acca823774 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/Setting/Setting.cs +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/Setting/Setting.cs @@ -8,6 +8,8 @@ using Windows.UI.Xaml.Controls; namespace Microsoft.PowerToys.Settings.UI.Controls { + [TemplateVisualState(Name = "Normal", GroupName = "CommonStates")] + [TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")] [TemplatePart(Name = PartIconPresenter, Type = typeof(ContentPresenter))] [TemplatePart(Name = PartDescriptionPresenter, Type = typeof(ContentPresenter))] public class Setting : ContentControl @@ -75,11 +77,14 @@ namespace Microsoft.PowerToys.Settings.UI.Controls protected override void OnApplyTemplate() { - base.OnApplyTemplate(); + IsEnabledChanged -= Setting_IsEnabledChanged; _setting = (Setting)this; _iconPresenter = (ContentPresenter)_setting.GetTemplateChild(PartIconPresenter); _descriptionPresenter = (ContentPresenter)_setting.GetTemplateChild(PartDescriptionPresenter); Update(); + SetEnabledState(); + IsEnabledChanged += Setting_IsEnabledChanged; + base.OnApplyTemplate(); } private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -92,6 +97,16 @@ namespace Microsoft.PowerToys.Settings.UI.Controls ((Setting)d).Update(); } + private void Setting_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) + { + SetEnabledState(); + } + + private void SetEnabledState() + { + VisualStateManager.GoToState(this, IsEnabled ? "Normal" : "Disabled", true); + } + private void Update() { if (_setting == null) diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/Setting/Setting.xaml b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/Setting/Setting.xaml index c921b87bd4..411b3a1465 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/Setting/Setting.xaml +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/Setting/Setting.xaml @@ -27,7 +27,10 @@ - + + + +