From 75d86fd260864823fd02cfc8f1358cba9293dcf1 Mon Sep 17 00:00:00 2001 From: Marcel Wagner Date: Fri, 9 Oct 2020 10:39:05 +0200 Subject: [PATCH 1/4] Add test --- dev/TeachingTip/APITests/TeachingTipTests.cs | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/dev/TeachingTip/APITests/TeachingTipTests.cs b/dev/TeachingTip/APITests/TeachingTipTests.cs index 84dd714ca1..5badfe3b68 100644 --- a/dev/TeachingTip/APITests/TeachingTipTests.cs +++ b/dev/TeachingTip/APITests/TeachingTipTests.cs @@ -203,6 +203,29 @@ public void PropagatePropertiesDown() }); } + [TestMethod] + public void VerifySubTitleBlockVisibilityOnInitialUnset() + { + TeachingTip teachingTip = null; + RunOnUIThread.Execute(() => + { + teachingTip = new TeachingTip(); + teachingTip.IsOpen = true; + Content = teachingTip; + }); + + IdleSynchronizer.Wait(); + + RunOnUIThread.Execute(() => + { + Verify.AreEqual("", teachingTip.Title); + Verify.AreEqual(Visibility.Collapsed, + TeachingTipTestHooks.GetTitleVisibility(teachingTip)); + Verify.AreEqual("", teachingTip.Subtitle); + Verify.AreEqual(Visibility.Collapsed, + TeachingTipTestHooks.GetSubtitleVisibility(teachingTip)); + }); + } [TestMethod] public void TeachingTipHeroContentPlacementTest() From b1ca3eb06385f0603b53d4cbceadf2ee218658a4 Mon Sep 17 00:00:00 2001 From: Marcel Wagner Date: Fri, 9 Oct 2020 10:39:14 +0200 Subject: [PATCH 2/4] Fix bug --- dev/TeachingTip/TeachingTip.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/dev/TeachingTip/TeachingTip.cpp b/dev/TeachingTip/TeachingTip.cpp index cb329e315f..c1908447f4 100644 --- a/dev/TeachingTip/TeachingTip.cpp +++ b/dev/TeachingTip/TeachingTip.cpp @@ -1,4 +1,4 @@ -#include "pch.h" +#include "pch.h" #include "common.h" #include "TeachingTip.h" #include "RuntimeProfiler.h" @@ -49,8 +49,25 @@ void TeachingTip::OnApplyTemplate() m_closeButton.set(GetTemplateChildT(s_closeButtonName, controlProtected)); m_tailEdgeBorder.set(GetTemplateChildT(s_tailEdgeBorderName, controlProtected)); m_tailPolygon.set(GetTemplateChildT(s_tailPolygonName, controlProtected)); - m_titleTextBox.set(GetTemplateChildT(s_titleTextBoxName, controlProtected)); - m_subtitleTextBox.set(GetTemplateChildT(s_subtitleTextBoxName, controlProtected)); + [this](const winrt::UIElement textBlock) + { + m_titleTextBox.set(textBlock); + if (textBlock != nullptr) + { + ToggleVisibilityForEmptyContent(textBlock, Title()); + } + + }(GetTemplateChildT(s_titleTextBoxName, controlProtected)); + [this](const winrt::UIElement textBlock) + { + m_subtitleTextBox.set(textBlock); + if (textBlock != nullptr) + { + ToggleVisibilityForEmptyContent(textBlock, Subtitle()); + } + + }(GetTemplateChildT(s_subtitleTextBoxName, controlProtected)); + if (auto&& container = m_container.get()) { From 93be3d2ec4b2f6245a2167c4032bf50742a3e4ee Mon Sep 17 00:00:00 2001 From: Marcel Wagner Date: Fri, 9 Oct 2020 21:56:06 +0200 Subject: [PATCH 3/4] Update variable names --- dev/TeachingTip/TeachingTip.cpp | 12 ++++++------ dev/TeachingTip/TeachingTip.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dev/TeachingTip/TeachingTip.cpp b/dev/TeachingTip/TeachingTip.cpp index c1908447f4..6440a598e5 100644 --- a/dev/TeachingTip/TeachingTip.cpp +++ b/dev/TeachingTip/TeachingTip.cpp @@ -51,7 +51,7 @@ void TeachingTip::OnApplyTemplate() m_tailPolygon.set(GetTemplateChildT(s_tailPolygonName, controlProtected)); [this](const winrt::UIElement textBlock) { - m_titleTextBox.set(textBlock); + m_titleTextBlock.set(textBlock); if (textBlock != nullptr) { ToggleVisibilityForEmptyContent(textBlock, Title()); @@ -60,7 +60,7 @@ void TeachingTip::OnApplyTemplate() }(GetTemplateChildT(s_titleTextBoxName, controlProtected)); [this](const winrt::UIElement textBlock) { - m_subtitleTextBox.set(textBlock); + m_subtitleTextBlock.set(textBlock); if (textBlock != nullptr) { ToggleVisibilityForEmptyContent(textBlock, Subtitle()); @@ -190,14 +190,14 @@ void TeachingTip::OnPropertyChanged(const winrt::DependencyPropertyChangedEventA else if (property == s_TitleProperty) { SetPopupAutomationProperties(); - if (ToggleVisibilityForEmptyContent(m_titleTextBox.get(), Title())) + if (ToggleVisibilityForEmptyContent(m_titleTextBlock.get(), Title())) { TeachingTipTestHooks::NotifyTitleVisibilityChanged(*this); } } else if (property == s_SubtitleProperty) { - if (ToggleVisibilityForEmptyContent(m_subtitleTextBox.get(), Subtitle())) + if (ToggleVisibilityForEmptyContent(m_subtitleTextBlock.get(), Subtitle())) { TeachingTipTestHooks::NotifySubtitleVisibilityChanged(*this); } @@ -2421,7 +2421,7 @@ double TeachingTip::GetVerticalOffset() winrt::Visibility TeachingTip::GetTitleVisibility() { - if (auto&& titleTextBox = m_titleTextBox.get()) + if (auto&& titleTextBox = m_titleTextBlock.get()) { return titleTextBox.Visibility(); } @@ -2430,7 +2430,7 @@ winrt::Visibility TeachingTip::GetTitleVisibility() winrt::Visibility TeachingTip::GetSubtitleVisibility() { - if (auto&& subtitleTextBox = m_subtitleTextBox.get()) + if (auto&& subtitleTextBox = m_subtitleTextBlock.get()) { return subtitleTextBox.Visibility(); } diff --git a/dev/TeachingTip/TeachingTip.h b/dev/TeachingTip/TeachingTip.h index 15f54b868c..77b3c7ac42 100644 --- a/dev/TeachingTip/TeachingTip.h +++ b/dev/TeachingTip/TeachingTip.h @@ -178,8 +178,8 @@ class TeachingTip : tracker_ref m_closeButton{ this }; tracker_ref m_tailPolygon{ this }; tracker_ref m_tailEdgeBorder{ this }; - tracker_ref m_titleTextBox{ this }; - tracker_ref m_subtitleTextBox{ this }; + tracker_ref m_titleTextBlock{ this }; + tracker_ref m_subtitleTextBlock{ this }; weak_ref m_previouslyFocusedElement{ }; From 5c6042195ccaf2594dbbaa333dc1166065c50413 Mon Sep 17 00:00:00 2001 From: Marcel Wagner Date: Fri, 16 Oct 2020 19:41:51 +0200 Subject: [PATCH 4/4] Update TeachingTip to use visual states to collapse title and subtitle --- dev/TeachingTip/TeachingTip.cpp | 63 ++++++++++++-------------------- dev/TeachingTip/TeachingTip.h | 2 +- dev/TeachingTip/TeachingTip.xaml | 20 +++++++++- 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/dev/TeachingTip/TeachingTip.cpp b/dev/TeachingTip/TeachingTip.cpp index 6440a598e5..f28af55190 100644 --- a/dev/TeachingTip/TeachingTip.cpp +++ b/dev/TeachingTip/TeachingTip.cpp @@ -10,6 +10,11 @@ #include "../ResourceHelper/Utils.h" #include +static constexpr auto c_TitleTextBlockVisibleStateName = L"ShowTitleTextBlock"sv; +static constexpr auto c_TitleTextBlockCollapsedStateName = L"CollapseTitleTextBlock"sv; +static constexpr auto c_SubtitleTextBlockVisibleStateName = L"ShowSubtitleTextBlock"sv; +static constexpr auto c_SubtitleTextBlockCollapsedStateName = L"CollapseSubtitleTextBlock"sv; + TeachingTip::TeachingTip() { __RP_Marker_ClassById(RuntimeProfiler::ProfId_TeachingTip); @@ -28,6 +33,8 @@ winrt::AutomationPeer TeachingTip::OnCreateAutomationPeer() void TeachingTip::OnApplyTemplate() { + base_type::OnApplyTemplate(); + m_acceleratorKeyActivatedRevoker.revoke(); m_effectiveViewportChangedRevoker.revoke(); m_contentSizeChangedRevoker.revoke(); @@ -49,24 +56,8 @@ void TeachingTip::OnApplyTemplate() m_closeButton.set(GetTemplateChildT(s_closeButtonName, controlProtected)); m_tailEdgeBorder.set(GetTemplateChildT(s_tailEdgeBorderName, controlProtected)); m_tailPolygon.set(GetTemplateChildT(s_tailPolygonName, controlProtected)); - [this](const winrt::UIElement textBlock) - { - m_titleTextBlock.set(textBlock); - if (textBlock != nullptr) - { - ToggleVisibilityForEmptyContent(textBlock, Title()); - } - - }(GetTemplateChildT(s_titleTextBoxName, controlProtected)); - [this](const winrt::UIElement textBlock) - { - m_subtitleTextBlock.set(textBlock); - if (textBlock != nullptr) - { - ToggleVisibilityForEmptyContent(textBlock, Subtitle()); - } - - }(GetTemplateChildT(s_subtitleTextBoxName, controlProtected)); + ToggleVisibilityForEmptyContent(c_TitleTextBlockVisibleStateName, c_TitleTextBlockCollapsedStateName, Title()); + ToggleVisibilityForEmptyContent(c_SubtitleTextBlockVisibleStateName, c_SubtitleTextBlockCollapsedStateName, Subtitle()); if (auto&& container = m_container.get()) @@ -190,14 +181,14 @@ void TeachingTip::OnPropertyChanged(const winrt::DependencyPropertyChangedEventA else if (property == s_TitleProperty) { SetPopupAutomationProperties(); - if (ToggleVisibilityForEmptyContent(m_titleTextBlock.get(), Title())) + if (ToggleVisibilityForEmptyContent(c_TitleTextBlockVisibleStateName, c_TitleTextBlockCollapsedStateName, Title())) { TeachingTipTestHooks::NotifyTitleVisibilityChanged(*this); } } else if (property == s_SubtitleProperty) { - if (ToggleVisibilityForEmptyContent(m_subtitleTextBlock.get(), Subtitle())) + if (ToggleVisibilityForEmptyContent(c_SubtitleTextBlockVisibleStateName, c_SubtitleTextBlockCollapsedStateName, Subtitle())) { TeachingTipTestHooks::NotifySubtitleVisibilityChanged(*this); } @@ -205,26 +196,18 @@ void TeachingTip::OnPropertyChanged(const winrt::DependencyPropertyChangedEventA } -bool TeachingTip::ToggleVisibilityForEmptyContent(const winrt::UIElement& element, const winrt::hstring& content) +bool TeachingTip::ToggleVisibilityForEmptyContent(const wstring_view visibleStateName, const wstring_view collapsedStateName, const winrt::hstring& content) { - if (element) + + if (content != L"") { - if (content != L"") - { - if (element.Visibility() == winrt::Visibility::Collapsed) - { - element.Visibility(winrt::Visibility::Visible); - return true; - } - } - else - { - if (element.Visibility() == winrt::Visibility::Visible) - { - element.Visibility(winrt::Visibility::Collapsed); - return true; - } - } + winrt::VisualStateManager::GoToState(*this, visibleStateName, false); + return true; + } + else + { + winrt::VisualStateManager::GoToState(*this, collapsedStateName, false); + return true; } return false; } @@ -2421,7 +2404,7 @@ double TeachingTip::GetVerticalOffset() winrt::Visibility TeachingTip::GetTitleVisibility() { - if (auto&& titleTextBox = m_titleTextBlock.get()) + if (auto&& titleTextBox = GetTemplateChildT(s_titleTextBoxName, *this)) { return titleTextBox.Visibility(); } @@ -2430,7 +2413,7 @@ winrt::Visibility TeachingTip::GetTitleVisibility() winrt::Visibility TeachingTip::GetSubtitleVisibility() { - if (auto&& subtitleTextBox = m_subtitleTextBlock.get()) + if (auto&& subtitleTextBox = GetTemplateChildT(s_subtitleTextBoxName, *this)) { return subtitleTextBox.Visibility(); } diff --git a/dev/TeachingTip/TeachingTip.h b/dev/TeachingTip/TeachingTip.h index 77b3c7ac42..ff3635af98 100644 --- a/dev/TeachingTip/TeachingTip.h +++ b/dev/TeachingTip/TeachingTip.h @@ -152,7 +152,7 @@ class TeachingTip : static std::array GetPlacementFallbackOrder(winrt::TeachingTipPlacementMode preferredPalcement); void EstablishShadows(); void TrySetCenterPoint(const winrt::IUIElement9& element, const winrt::float3& centerPoint); - bool ToggleVisibilityForEmptyContent(const winrt::UIElement& element, const winrt::hstring& content); + bool ToggleVisibilityForEmptyContent(const wstring_view visibleStateName, const wstring_view collapsedStateName, const winrt::hstring& content); // The tail is designed as an 8x16 pixel shape, however it is actually a 10x20 shape which is partially occluded by the tip content. // This is done to get the border of the tip to follow the tail shape without drawing the border on the tip edge of the tail. diff --git a/dev/TeachingTip/TeachingTip.xaml b/dev/TeachingTip/TeachingTip.xaml index 715016bb87..e51a0c3f42 100644 --- a/dev/TeachingTip/TeachingTip.xaml +++ b/dev/TeachingTip/TeachingTip.xaml @@ -465,6 +465,22 @@ + + + + + + + + + + + + + + + + + FontWeight="SemiBold" Visibility="Collapsed"/> + TextWrapping="WrapWholeWords" Visibility="Collapsed"/>