Skip to content

Commit

Permalink
Fix initial render bug
Browse files Browse the repository at this point in the history
  • Loading branch information
niels9001 committed Nov 6, 2023
1 parent 20c08ac commit 01462e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
25 changes: 19 additions & 6 deletions components/SettingsControls/src/SettingsCard/SettingsCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<Thickness x:Key="SettingsCardHeaderIconMargin">2,0,20,0</Thickness>
<Thickness x:Key="SettingsCardActionIconMargin">14,0,0,0</Thickness>
<x:Double x:Key="SettingsCardActionIconMaxSize">13</x:Double>
<x:Double x:Key="SettingsCardVerticalHeaderContentSpacing">36</x:Double>
<x:Double x:Key="SettingsCardVerticalHeaderContentSpacing">8</x:Double>
<x:Double x:Key="SettingsCardWrapThreshold">476</x:Double>
<x:Double x:Key="SettingsCardWrapNoIconThreshold">286</x:Double>

Expand Down

0 comments on commit 01462e1

Please sign in to comment.