mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
IsEnabled state support
This commit is contained in:
@@ -20,7 +20,7 @@
|
|||||||
<ResourceDictionary Source="/Themes/SettingsSectionStyles.xaml"/>
|
<ResourceDictionary Source="/Themes/SettingsSectionStyles.xaml"/>
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
|
||||||
<Thickness x:Key="InfoBarIconMargin">6,16,20,16</Thickness>
|
<Thickness x:Key="InfoBarIconMargin">6,16,16,16</Thickness>
|
||||||
|
|
||||||
<Thickness x:Key="InfoBarContentRootPadding">16,0,0,0</Thickness>
|
<Thickness x:Key="InfoBarContentRootPadding">16,0,0,0</Thickness>
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ using Windows.UI.Xaml.Controls;
|
|||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.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 = PartIconPresenter, Type = typeof(ContentPresenter))]
|
||||||
[TemplatePart(Name = PartDescriptionPresenter, Type = typeof(ContentPresenter))]
|
[TemplatePart(Name = PartDescriptionPresenter, Type = typeof(ContentPresenter))]
|
||||||
public class Setting : ContentControl
|
public class Setting : ContentControl
|
||||||
@@ -75,11 +77,14 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
|
|||||||
|
|
||||||
protected override void OnApplyTemplate()
|
protected override void OnApplyTemplate()
|
||||||
{
|
{
|
||||||
base.OnApplyTemplate();
|
IsEnabledChanged -= Setting_IsEnabledChanged;
|
||||||
_setting = (Setting)this;
|
_setting = (Setting)this;
|
||||||
_iconPresenter = (ContentPresenter)_setting.GetTemplateChild(PartIconPresenter);
|
_iconPresenter = (ContentPresenter)_setting.GetTemplateChild(PartIconPresenter);
|
||||||
_descriptionPresenter = (ContentPresenter)_setting.GetTemplateChild(PartDescriptionPresenter);
|
_descriptionPresenter = (ContentPresenter)_setting.GetTemplateChild(PartDescriptionPresenter);
|
||||||
Update();
|
Update();
|
||||||
|
SetEnabledState();
|
||||||
|
IsEnabledChanged += Setting_IsEnabledChanged;
|
||||||
|
base.OnApplyTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
@@ -92,6 +97,16 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
|
|||||||
((Setting)d).Update();
|
((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()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (_setting == null)
|
if (_setting == null)
|
||||||
|
|||||||
@@ -27,7 +27,10 @@
|
|||||||
<VisualState x:Name="Normal"/>
|
<VisualState x:Name="Normal"/>
|
||||||
<VisualState x:Name="Disabled">
|
<VisualState x:Name="Disabled">
|
||||||
<VisualState.Setters>
|
<VisualState.Setters>
|
||||||
<Setter Target="RootGrid.Background" Value="Red" />
|
<Setter Target="HeaderPresenter.Foreground" Value="{ThemeResource TextFillColorDisabledBrush}" />
|
||||||
|
<Setter Target="DescriptionPresenter.Foreground" Value="{ThemeResource TextFillColorDisabledBrush}" />
|
||||||
|
<Setter Target="IconPresenter.Foreground" Value="{ThemeResource TextFillColorDisabledBrush}" />
|
||||||
|
<Setter Target="ContentPresenter.Foreground" Value="{ThemeResource TextFillColorDisabledBrush}" />
|
||||||
</VisualState.Setters>
|
</VisualState.Setters>
|
||||||
</VisualState>
|
</VisualState>
|
||||||
</VisualStateGroup>
|
</VisualStateGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user