Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TeachingTip: Fix HeroContentPlacement being ignored when initially set from XAML markup #3271

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 57 additions & 2 deletions dev/TeachingTip/APITests/TeachingTipTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using IconSource = Microsoft.UI.Xaml.Controls.IconSource;
using SymbolIconSource = Microsoft.UI.Xaml.Controls.SymbolIconSource;
using Microsoft.UI.Private.Controls;
using Microsoft.UI.Xaml.Controls;

namespace Windows.UI.Xaml.Tests.MUXControls.ApiTests
{
Expand Down Expand Up @@ -167,7 +168,6 @@ public void TeachingTipWithContentAndWithoutIconSourceDoesNotCrash()
loadedEvent.WaitOne();
}


[TestMethod]
public void PropagatePropertiesDown()
{
Expand Down Expand Up @@ -201,8 +201,63 @@ public void PropagatePropertiesDown()
var foregroundBrush = content.Foreground as SolidColorBrush;
Verify.AreEqual(Colors.Red, foregroundBrush.Color);
});

}


[TestMethod]
public void TeachingTipHeroContentPlacementTest()
{
RunOnUIThread.Execute(() =>
{
foreach (var iPlacementMode in Enum.GetValues(typeof(TeachingTipHeroContentPlacementMode)))
{
var placementMode = (TeachingTipHeroContentPlacementMode)iPlacementMode;

Log.Comment($"Verifying TeachingTipHeroContentPlacementMode [{placementMode}]");

TeachingTip teachingTip = new TeachingTip();
teachingTip.HeroContentPlacement = placementMode;

// Open the teaching tip to enter the correct visual state for the HeroContentPlacement.
teachingTip.IsOpen = true;

Content = teachingTip;
Content.UpdateLayout();

Verify.IsTrue(teachingTip.HeroContentPlacement == placementMode, $"HeroContentPlacement should have been [{placementMode}]");

var root = VisualTreeUtils.FindVisualChildByName(teachingTip, "Container") as FrameworkElement;

switch (placementMode)
{
case TeachingTipHeroContentPlacementMode.Auto:
Verify.IsTrue(IsVisualStateActive(root, "HeroContentPlacementStates", "HeroContentTop"),
"The [HeroContentTop] visual state should have been active");
break;
case TeachingTipHeroContentPlacementMode.Top:
Verify.IsTrue(IsVisualStateActive(root, "HeroContentPlacementStates", "HeroContentTop"),
"The [HeroContentTop] visual state should have been active");
break;
case TeachingTipHeroContentPlacementMode.Bottom:
Verify.IsTrue(IsVisualStateActive(root, "HeroContentPlacementStates", "HeroContentBottom"),
"The [HeroContentBottom] visual state should have been active");
break;
}
}
});

bool IsVisualStateActive(FrameworkElement root, string groupName, string stateName)
{
foreach (var group in VisualStateManager.GetVisualStateGroups(root))
{
if (group.Name == groupName)
{
return group.CurrentState != null && group.CurrentState.Name == stateName;
}
}

return false;
}
}
}
}
49 changes: 25 additions & 24 deletions dev/TeachingTip/TeachingTip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ void TeachingTip::OnApplyTemplate()
UpdateButtonsState();
OnIsLightDismissEnabledChanged();
OnIconSourceChanged();
OnHeroContentPlacementChanged();

EstablishShadows();

Expand Down Expand Up @@ -747,25 +748,35 @@ void TeachingTip::UpdateDynamicHeroContentPlacementToTop()
{
if (HeroContentPlacement() == winrt::TeachingTipHeroContentPlacementMode::Auto)
{
winrt::VisualStateManager::GoToState(*this, L"HeroContentTop"sv, false);
if (m_currentHeroContentEffectivePlacementMode != winrt::TeachingTipHeroContentPlacementMode::Top)
{
m_currentHeroContentEffectivePlacementMode = winrt::TeachingTipHeroContentPlacementMode::Top;
TeachingTipTestHooks::NotifyEffectiveHeroContentPlacementChanged(*this);
}
UpdateDynamicHeroContentPlacementToTopImpl();
}
}

void TeachingTip::UpdateDynamicHeroContentPlacementToTopImpl()
{
winrt::VisualStateManager::GoToState(*this, L"HeroContentTop"sv, false);
if (m_currentHeroContentEffectivePlacementMode != winrt::TeachingTipHeroContentPlacementMode::Top)
{
m_currentHeroContentEffectivePlacementMode = winrt::TeachingTipHeroContentPlacementMode::Top;
TeachingTipTestHooks::NotifyEffectiveHeroContentPlacementChanged(*this);
}
}

void TeachingTip::UpdateDynamicHeroContentPlacementToBottom()
{
if (HeroContentPlacement() == winrt::TeachingTipHeroContentPlacementMode::Auto)
{
winrt::VisualStateManager::GoToState(*this, L"HeroContentBottom"sv, false);
if (m_currentHeroContentEffectivePlacementMode != winrt::TeachingTipHeroContentPlacementMode::Bottom)
{
m_currentHeroContentEffectivePlacementMode = winrt::TeachingTipHeroContentPlacementMode::Bottom;
TeachingTipTestHooks::NotifyEffectiveHeroContentPlacementChanged(*this);
}
UpdateDynamicHeroContentPlacementToBottomImpl();
}
}

void TeachingTip::UpdateDynamicHeroContentPlacementToBottomImpl()
{
winrt::VisualStateManager::GoToState(*this, L"HeroContentBottom"sv, false);
if (m_currentHeroContentEffectivePlacementMode != winrt::TeachingTipHeroContentPlacementMode::Bottom)
{
m_currentHeroContentEffectivePlacementMode = winrt::TeachingTipHeroContentPlacementMode::Bottom;
TeachingTipTestHooks::NotifyEffectiveHeroContentPlacementChanged(*this);
}
}

Expand Down Expand Up @@ -1003,20 +1014,10 @@ void TeachingTip::OnHeroContentPlacementChanged()
case winrt::TeachingTipHeroContentPlacementMode::Auto:
break;
case winrt::TeachingTipHeroContentPlacementMode::Top:
winrt::VisualStateManager::GoToState(*this, L"HeroContentTop"sv, false);
if (m_currentHeroContentEffectivePlacementMode != winrt::TeachingTipHeroContentPlacementMode::Top)
{
m_currentHeroContentEffectivePlacementMode = winrt::TeachingTipHeroContentPlacementMode::Top;
TeachingTipTestHooks::NotifyEffectiveHeroContentPlacementChanged(*this);
}
UpdateDynamicHeroContentPlacementToTopImpl();
break;
case winrt::TeachingTipHeroContentPlacementMode::Bottom:
winrt::VisualStateManager::GoToState(*this, L"HeroContentBottom"sv, false);
if (m_currentHeroContentEffectivePlacementMode != winrt::TeachingTipHeroContentPlacementMode::Bottom)
{
m_currentHeroContentEffectivePlacementMode = winrt::TeachingTipHeroContentPlacementMode::Bottom;
TeachingTipTestHooks::NotifyEffectiveHeroContentPlacementChanged(*this);
}
UpdateDynamicHeroContentPlacementToBottomImpl();
break;
}

Expand Down
2 changes: 2 additions & 0 deletions dev/TeachingTip/TeachingTip.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class TeachingTip :
void UpdateButtonsState();
void UpdateDynamicHeroContentPlacementToTop();
void UpdateDynamicHeroContentPlacementToBottom();
void UpdateDynamicHeroContentPlacementToTopImpl();
void UpdateDynamicHeroContentPlacementToBottomImpl();

static void OnPropertyChanged(
const winrt::DependencyObject& sender,
Expand Down