diff --git a/components/SettingsControls/src/SettingsCard/SettingsCard.cs b/components/SettingsControls/src/SettingsCard/SettingsCard.cs index 582a16fe..ba645331 100644 --- a/components/SettingsControls/src/SettingsCard/SettingsCard.cs +++ b/components/SettingsControls/src/SettingsCard/SettingsCard.cs @@ -73,17 +73,24 @@ protected override void OnApplyTemplate() OnHeaderIconChanged(); OnDescriptionChanged(); OnIsClickEnabledChanged(); - VisualStateManager.GoToState(this, IsEnabled ? NormalState : DisabledState, true); + CheckInitialVisualState(); + RegisterAutomation(); RegisterPropertyChangedCallback(ContentProperty, OnContentChanged); + IsEnabledChanged += OnIsEnabledChanged; + } + + private void CheckInitialVisualState() + { + VisualStateManager.GoToState(this, IsEnabled ? NormalState : DisabledState, true); - if (GetTemplateChild("ContentAlignmentStates") is VisualStateGroup actionIconPresenter) + if (GetTemplateChild("ContentAlignmentStates") is VisualStateGroup contentAlignmentStatesGroup) { - actionIconPresenter.CurrentStateChanged += this.ContentAlignmentStates_Changed; + contentAlignmentStatesGroup.CurrentStateChanged -= this.ContentAlignmentStates_Changed; + CheckVerticalSpacingState(contentAlignmentStatesGroup.CurrentState); + contentAlignmentStatesGroup.CurrentStateChanged += this.ContentAlignmentStates_Changed; } - IsEnabledChanged += OnIsEnabledChanged; } - private void RegisterAutomation() { if (Header is string headerString && headerString != string.Empty) @@ -259,9 +266,15 @@ private void OnHeaderChanged() } private void ContentAlignmentStates_Changed(object sender, VisualStateChangedEventArgs e) + { + CheckVerticalSpacingState(e.NewState); + } + + private void CheckVerticalSpacingState(VisualState s) { // On state change, checking if the Content should be wrapped (e.g. when the card is made smaller or the ContentAlignment is set to Vertical). If the Content and the Header or Description are not null, we add spacing between the Content and the Header/Description. - if (e.NewState != null && (e.NewState.Name == RightWrappedState || e.NewState.Name == RightWrappedNoIconState || e.NewState.Name == VerticalState) && (Content != null) && (Header != null || Description != null)) + + if (s != null && (s.Name == RightWrappedState || s.Name == RightWrappedNoIconState || s.Name == VerticalState) && (Content != null) && (Header != null || Description != null)) { VisualStateManager.GoToState(this, ContentSpacingState, true); } diff --git a/components/SettingsControls/src/SettingsCard/SettingsCard.xaml b/components/SettingsControls/src/SettingsCard/SettingsCard.xaml index d5c1135b..d993a5af 100644 --- a/components/SettingsControls/src/SettingsCard/SettingsCard.xaml +++ b/components/SettingsControls/src/SettingsCard/SettingsCard.xaml @@ -106,7 +106,7 @@ 2,0,20,0 14,0,0,0 13 - 36 + 8 476 286