Skip to content

Commit

Permalink
Fix crash on setting string.Empty in SettingsCard
Browse files Browse the repository at this point in the history
  • Loading branch information
Dub1shu authored and Arlodotexe committed Jan 9, 2024
1 parent 8e4bd7a commit 6a4b863
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions components/SettingsControls/src/SettingsCard/SettingsCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,20 @@ private void OnDescriptionChanged()
{
if (GetTemplateChild(DescriptionPresenter) is FrameworkElement descriptionPresenter)
{
descriptionPresenter.Visibility = Description != null
? Visibility.Visible
: Visibility.Collapsed;
descriptionPresenter.Visibility = IsNullOrEmptyString(Description)
? Visibility.Collapsed
: Visibility.Visible;
}

}

private void OnHeaderChanged()
{
if (GetTemplateChild(HeaderPresenter) is FrameworkElement headerPresenter)
{
headerPresenter.Visibility = Header != null
? Visibility.Visible
: Visibility.Collapsed;
headerPresenter.Visibility = IsNullOrEmptyString(Header)
? Visibility.Collapsed
: Visibility.Visible;
}

}
Expand All @@ -274,7 +274,7 @@ 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 (s != null && (s.Name == RightWrappedState || s.Name == RightWrappedNoIconState || s.Name == VerticalState) && (Content != null) && (Header != null || Description != null))
if (s != null && (s.Name == RightWrappedState || s.Name == RightWrappedNoIconState || s.Name == VerticalState) && (Content != null) && (!IsNullOrEmptyString(Header) || !IsNullOrEmptyString(Description)))
{
VisualStateManager.GoToState(this, ContentSpacingState, true);
}
Expand All @@ -295,4 +295,19 @@ private void CheckVerticalSpacingState(VisualState s)
return FocusManager.GetFocusedElement() as FrameworkElement;
}
}

private static bool IsNullOrEmptyString(object obj)
{
if (obj == null)
{
return true;
}

if (obj is string objString && objString == string.Empty)
{
return true;
}

return false;
}
}

0 comments on commit 6a4b863

Please sign in to comment.