diff --git a/components/SettingsControls/src/SettingsCard/SettingsCard.cs b/components/SettingsControls/src/SettingsCard/SettingsCard.cs index dbc4f12e..ef1d4a09 100644 --- a/components/SettingsControls/src/SettingsCard/SettingsCard.cs +++ b/components/SettingsControls/src/SettingsCard/SettingsCard.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.ComponentModel.Design; - namespace CommunityToolkit.WinUI.Controls; /// @@ -21,6 +19,9 @@ namespace CommunityToolkit.WinUI.Controls; [TemplateVisualState(Name = PressedState, GroupName = CommonStates)] [TemplateVisualState(Name = DisabledState, GroupName = CommonStates)] +[TemplateVisualState(Name = BitmapHeaderIconEnabledState, GroupName = BitmapHeaderIconStates)] +[TemplateVisualState(Name = BitmapHeaderIconDisabledState, GroupName = BitmapHeaderIconStates)] + [TemplateVisualState(Name = RightState, GroupName = ContentAlignmentStates)] [TemplateVisualState(Name = RightWrappedState, GroupName = ContentAlignmentStates)] [TemplateVisualState(Name = RightWrappedNoIconState, GroupName = ContentAlignmentStates)] @@ -38,6 +39,10 @@ public partial class SettingsCard : ButtonBase internal const string PressedState = "Pressed"; internal const string DisabledState = "Disabled"; + internal const string BitmapHeaderIconStates = "BitmapHeaderIconStates"; + internal const string BitmapHeaderIconEnabledState = "BitmapHeaderIconEnabled"; + internal const string BitmapHeaderIconDisabledState = "BitmapHeaderIconDisabled"; + internal const string ContentAlignmentStates = "ContentAlignmentStates"; internal const string RightState = "Right"; internal const string RightWrappedState = "RightWrapped"; @@ -76,7 +81,7 @@ protected override void OnApplyTemplate() CheckInitialVisualState(); SetAccessibleContentName(); RegisterPropertyChangedCallback(ContentProperty, OnContentChanged); - IsEnabledChanged += OnIsEnabledChanged; + IsEnabledChanged += OnIsEnabledChanged; } private void CheckInitialVisualState() @@ -89,6 +94,8 @@ private void CheckInitialVisualState() CheckVerticalSpacingState(contentAlignmentStatesGroup.CurrentState); contentAlignmentStatesGroup.CurrentStateChanged += this.ContentAlignmentStates_Changed; } + + CheckHeaderIconState(); } // We automatically set the AutomationProperties.Name of the Content if not configured. @@ -183,7 +190,6 @@ private void Control_PointerCanceled(object sender, PointerRoutedEventArgs e) /// protected override void OnPointerPressed(PointerRoutedEventArgs e) { - // e.Handled = true; if (IsClickEnabled) { base.OnPointerPressed(e); @@ -228,6 +234,18 @@ private void OnIsClickEnabledChanged() private void OnIsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) { VisualStateManager.GoToState(this, IsEnabled ? NormalState : DisabledState, true); + + CheckHeaderIconState(); + } + + private void CheckHeaderIconState() + { + // The Disabled visual state will only set the right Foreground brush, but for images we need to lower the opacity so it looks disabled. + + if (HeaderIcon is BitmapIcon) + { + VisualStateManager.GoToState(this, IsEnabled ? BitmapHeaderIconEnabledState : BitmapHeaderIconDisabledState, true); + } } private void OnActionIconChanged() @@ -240,7 +258,7 @@ private void OnActionIconChanged() } else { - actionIconPresenter.Visibility =Visibility.Collapsed; + actionIconPresenter.Visibility = Visibility.Collapsed; } } } diff --git a/components/SettingsControls/src/SettingsCard/SettingsCard.xaml b/components/SettingsControls/src/SettingsCard/SettingsCard.xaml index 3d2e4dd3..280caf7b 100644 --- a/components/SettingsControls/src/SettingsCard/SettingsCard.xaml +++ b/components/SettingsControls/src/SettingsCard/SettingsCard.xaml @@ -109,6 +109,7 @@ 8 476 286 + 0.4