Skip to content

Commit

Permalink
Merge branch 'main' into fix-colorlerprgb
Browse files Browse the repository at this point in the history
  • Loading branch information
Arlodotexe authored Jan 9, 2024
2 parents 869ba69 + eb98b48 commit eeffed6
Show file tree
Hide file tree
Showing 2 changed files with 37 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;
}
}
14 changes: 14 additions & 0 deletions components/SettingsControls/tests/Test_SettingsCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ namespace SettingsControlsExperiment.Tests;
[TestClass]
public partial class SettingsCardTestClass : VisualUITestBase
{
[UIThreadTestMethod]
public void EmptyNameTest(SettingsCard card)
{
// See https://github.com/CommunityToolkit/Windows/issues/310#issue-2066181868
card.Name = string.Empty;
}

[UIThreadTestMethod]
public void EmptyDescriptionTest(SettingsCard card)
{
// See https://github.com/CommunityToolkit/Windows/issues/310#issue-2066181868
card.Description = string.Empty;
}

// If you don't need access to UI objects directly or async code, use this pattern.
[TestMethod]
public void SimpleSynchronousExampleTest()
Expand Down

0 comments on commit eeffed6

Please sign in to comment.