Skip to content

Commit 6a4b863

Browse files
Dub1shuArlodotexe
authored andcommitted
Fix crash on setting string.Empty in SettingsCard
1 parent 8e4bd7a commit 6a4b863

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

components/SettingsControls/src/SettingsCard/SettingsCard.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,20 @@ private void OnDescriptionChanged()
247247
{
248248
if (GetTemplateChild(DescriptionPresenter) is FrameworkElement descriptionPresenter)
249249
{
250-
descriptionPresenter.Visibility = Description != null
251-
? Visibility.Visible
252-
: Visibility.Collapsed;
250+
descriptionPresenter.Visibility = IsNullOrEmptyString(Description)
251+
? Visibility.Collapsed
252+
: Visibility.Visible;
253253
}
254-
254+
255255
}
256256

257257
private void OnHeaderChanged()
258258
{
259259
if (GetTemplateChild(HeaderPresenter) is FrameworkElement headerPresenter)
260260
{
261-
headerPresenter.Visibility = Header != null
262-
? Visibility.Visible
263-
: Visibility.Collapsed;
261+
headerPresenter.Visibility = IsNullOrEmptyString(Header)
262+
? Visibility.Collapsed
263+
: Visibility.Visible;
264264
}
265265

266266
}
@@ -274,7 +274,7 @@ private void CheckVerticalSpacingState(VisualState s)
274274
{
275275
// 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.
276276

277-
if (s != null && (s.Name == RightWrappedState || s.Name == RightWrappedNoIconState || s.Name == VerticalState) && (Content != null) && (Header != null || Description != null))
277+
if (s != null && (s.Name == RightWrappedState || s.Name == RightWrappedNoIconState || s.Name == VerticalState) && (Content != null) && (!IsNullOrEmptyString(Header) || !IsNullOrEmptyString(Description)))
278278
{
279279
VisualStateManager.GoToState(this, ContentSpacingState, true);
280280
}
@@ -295,4 +295,19 @@ private void CheckVerticalSpacingState(VisualState s)
295295
return FocusManager.GetFocusedElement() as FrameworkElement;
296296
}
297297
}
298+
299+
private static bool IsNullOrEmptyString(object obj)
300+
{
301+
if (obj == null)
302+
{
303+
return true;
304+
}
305+
306+
if (obj is string objString && objString == string.Empty)
307+
{
308+
return true;
309+
}
310+
311+
return false;
312+
}
298313
}

0 commit comments

Comments
 (0)