22// The .NET Foundation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
5- using System . ComponentModel . Design ;
6-
75namespace CommunityToolkit . WinUI . Controls ;
86
97/// <summary>
@@ -21,6 +19,9 @@ namespace CommunityToolkit.WinUI.Controls;
2119[ TemplateVisualState ( Name = PressedState , GroupName = CommonStates ) ]
2220[ TemplateVisualState ( Name = DisabledState , GroupName = CommonStates ) ]
2321
22+ [ TemplateVisualState ( Name = BitmapHeaderIconEnabledState , GroupName = BitmapHeaderIconStates ) ]
23+ [ TemplateVisualState ( Name = BitmapHeaderIconDisabledState , GroupName = BitmapHeaderIconStates ) ]
24+
2425[ TemplateVisualState ( Name = RightState , GroupName = ContentAlignmentStates ) ]
2526[ TemplateVisualState ( Name = RightWrappedState , GroupName = ContentAlignmentStates ) ]
2627[ TemplateVisualState ( Name = RightWrappedNoIconState , GroupName = ContentAlignmentStates ) ]
@@ -38,6 +39,10 @@ public partial class SettingsCard : ButtonBase
3839 internal const string PressedState = "Pressed" ;
3940 internal const string DisabledState = "Disabled" ;
4041
42+ internal const string BitmapHeaderIconStates = "BitmapHeaderIconStates" ;
43+ internal const string BitmapHeaderIconEnabledState = "BitmapHeaderIconEnabled" ;
44+ internal const string BitmapHeaderIconDisabledState = "BitmapHeaderIconDisabled" ;
45+
4146 internal const string ContentAlignmentStates = "ContentAlignmentStates" ;
4247 internal const string RightState = "Right" ;
4348 internal const string RightWrappedState = "RightWrapped" ;
@@ -76,7 +81,7 @@ protected override void OnApplyTemplate()
7681 CheckInitialVisualState ( ) ;
7782 SetAccessibleContentName ( ) ;
7883 RegisterPropertyChangedCallback ( ContentProperty , OnContentChanged ) ;
79- IsEnabledChanged += OnIsEnabledChanged ;
84+ IsEnabledChanged += OnIsEnabledChanged ;
8085 }
8186
8287 private void CheckInitialVisualState ( )
@@ -89,6 +94,8 @@ private void CheckInitialVisualState()
8994 CheckVerticalSpacingState ( contentAlignmentStatesGroup . CurrentState ) ;
9095 contentAlignmentStatesGroup . CurrentStateChanged += this . ContentAlignmentStates_Changed ;
9196 }
97+
98+ CheckHeaderIconState ( ) ;
9299 }
93100
94101 // We automatically set the AutomationProperties.Name of the Content if not configured.
@@ -183,7 +190,6 @@ private void Control_PointerCanceled(object sender, PointerRoutedEventArgs e)
183190 /// </summary>
184191 protected override void OnPointerPressed ( PointerRoutedEventArgs e )
185192 {
186- // e.Handled = true;
187193 if ( IsClickEnabled )
188194 {
189195 base . OnPointerPressed ( e ) ;
@@ -228,6 +234,18 @@ private void OnIsClickEnabledChanged()
228234 private void OnIsEnabledChanged ( object sender , DependencyPropertyChangedEventArgs e )
229235 {
230236 VisualStateManager . GoToState ( this , IsEnabled ? NormalState : DisabledState , true ) ;
237+
238+ CheckHeaderIconState ( ) ;
239+ }
240+
241+ private void CheckHeaderIconState ( )
242+ {
243+ // The Disabled visual state will only set the right Foreground brush, but for images we need to lower the opacity so it looks disabled.
244+
245+ if ( HeaderIcon is BitmapIcon )
246+ {
247+ VisualStateManager . GoToState ( this , IsEnabled ? BitmapHeaderIconEnabledState : BitmapHeaderIconDisabledState , true ) ;
248+ }
231249 }
232250
233251 private void OnActionIconChanged ( )
@@ -240,7 +258,7 @@ private void OnActionIconChanged()
240258 }
241259 else
242260 {
243- actionIconPresenter . Visibility = Visibility . Collapsed ;
261+ actionIconPresenter . Visibility = Visibility . Collapsed ;
244262 }
245263 }
246264 }
0 commit comments