Skip to content

Commit

Permalink
Fix issue where TeachingTip's background is not correct for LightDism…
Browse files Browse the repository at this point in the history
…iss (#990)
  • Loading branch information
jevansaks authored and kmahone committed Aug 6, 2019
1 parent 7e34c09 commit c4c45e2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 14 deletions.
71 changes: 58 additions & 13 deletions dev/TeachingTip/APITests/TeachingTipTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,87 @@
using TeachingTip = Microsoft.UI.Xaml.Controls.TeachingTip;
using IconSource = Microsoft.UI.Xaml.Controls.IconSource;
using SymbolIconSource = Microsoft.UI.Xaml.Controls.SymbolIconSource;
using Microsoft.UI.Private.Controls;

namespace Windows.UI.Xaml.Tests.MUXControls.ApiTests
{
[TestClass]
public class TeachingTipTests
{
//[TestMethod] TODO: Re-enable once issue #643 is fixed.
[TestMethod]
[TestProperty("TestPass:IncludeOnlyOn", "Desktop")] // TeachingTip doesn't appear to show up correctly in OneCore.
public void TeachingTipBackgroundTest()
{
TeachingTip teachingTip = null, teachingTipLightDismiss = null;
SolidColorBrush blueBrush = null;
Brush lightDismissBackgroundBrush = null;
var loadedEvent = new AutoResetEvent(false);
RunOnUIThread.Execute(() =>
{
TeachingTip teachingTip = new TeachingTip();
Grid root = new Grid();
teachingTip = new TeachingTip();
teachingTip.Loaded += (object sender, RoutedEventArgs args) => { loadedEvent.Set(); };
MUXControlsTestApp.App.TestContentRoot = teachingTip;

teachingTipLightDismiss = new TeachingTip();
teachingTipLightDismiss.IsLightDismissEnabled = true;

// Set LightDismiss background before show... it shouldn't take effect in the tree
blueBrush = new SolidColorBrush(Colors.Blue);
teachingTipLightDismiss.Background = blueBrush;

root.Resources.Add("TeachingTip", teachingTip);
root.Resources.Add("TeachingTipLightDismiss", teachingTipLightDismiss);

lightDismissBackgroundBrush = MUXControlsTestApp.App.Current.Resources["TeachingTipTransientBackground"] as Brush;
Verify.IsNotNull(lightDismissBackgroundBrush, "lightDismissBackgroundBrush");

teachingTip.IsOpen = true;
teachingTipLightDismiss.IsOpen = true;

MUXControlsTestApp.App.TestContentRoot = root;
});

IdleSynchronizer.Wait();
loadedEvent.WaitOne();
IdleSynchronizer.Wait();

RunOnUIThread.Execute(() =>
{
TeachingTip teachingTip = (TeachingTip)MUXControlsTestApp.App.TestContentRoot;
var redBrush = new SolidColorBrush(Colors.Red);
teachingTip.SetValue(TeachingTip.BackgroundProperty, redBrush);
Verify.AreSame(redBrush, teachingTip.GetValue(TeachingTip.BackgroundProperty) as Brush);
Verify.AreSame(redBrush, teachingTip.Background);

var blueBrush = new SolidColorBrush(Colors.Blue);
teachingTip.Background = blueBrush;
Verify.AreSame(blueBrush, teachingTip.Background);

var child = VisualTreeHelper.GetChild(teachingTip, 0);
var grandChild = VisualTreeHelper.GetChild(child, 1);
Verify.AreSame(blueBrush, ((Grid)grandChild).Background);
{
var popup = TeachingTipTestHooks.GetPopup(teachingTip);
var child = popup.Child;
var grandChild = VisualTreeHelper.GetChild(child, 0);
Verify.AreSame(blueBrush, ((Grid)grandChild).Background, "Checking TeachingTip.Background TemplateBinding works");
}

{
var popup = TeachingTipTestHooks.GetPopup(teachingTipLightDismiss);
var child = popup.Child;
var grandChild = VisualTreeHelper.GetChild(child, 0);
var actualBrush = ((Grid)grandChild).Background;
Log.Comment("Checking LightDismiss TeachingTip Background is using resource for first invocation");
if (lightDismissBackgroundBrush != actualBrush)
{
if (actualBrush is SolidColorBrush actualSolidBrush)
{
string teachingTipMessage = $"LightDismiss TeachingTip Background is SolidColorBrush with color {actualSolidBrush.Color}";
Log.Comment(teachingTipMessage);
Verify.Fail(teachingTipMessage);
}
else
{
Verify.AreSame(lightDismissBackgroundBrush, actualBrush, "Checking LightDismiss TeachingTip Background is using resource for first invocation");
}
}
}

teachingTip.IsLightDismissEnabled = true;
});
Expand All @@ -68,15 +113,15 @@ public void TeachingTipBackgroundTest()

RunOnUIThread.Execute(() =>
{
TeachingTip teachingTip = (TeachingTip)MUXControlsTestApp.App.TestContentRoot;
var blueBrush = new SolidColorBrush(Colors.Blue);
Verify.AreEqual(blueBrush.Color, ((SolidColorBrush)teachingTip.Background).Color);
var child = VisualTreeHelper.GetChild(teachingTip, 0);
var grandChild = VisualTreeHelper.GetChild(child, 1);

var popup = TeachingTipTestHooks.GetPopup(teachingTip);
var child = popup.Child as Grid;
var grandChild = VisualTreeHelper.GetChild(child, 0);
var grandChildBackgroundBrush = ((Grid)grandChild).Background;
//If we can no longer cast the background brush to a solid color brush then changing the
//IsLightDismissEnabled has changed the background as we expected it to.
if(grandChildBackgroundBrush is SolidColorBrush)
if (grandChildBackgroundBrush is SolidColorBrush)
{
Verify.AreNotEqual(blueBrush.Color, ((SolidColorBrush)grandChildBackgroundBrush).Color);
}
Expand Down
5 changes: 4 additions & 1 deletion dev/TeachingTip/TeachingTip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void TeachingTip::OnApplyTemplate()
}();

UpdateButtonsState();

OnIsLightDismissEnabledChanged();
OnIconSourceChanged();

EstablishShadows();
Expand Down Expand Up @@ -833,6 +833,9 @@ void TeachingTip::IsOpenChangedToOpen()
}

m_acceleratorKeyActivatedRevoker = Dispatcher().AcceleratorKeyActivated(winrt::auto_revoke, { this, &TeachingTip::OnF6AcceleratorKeyClicked });

// Make sure we are in the correct VSM state after ApplyTemplate and moving the template content from the Control to the Popup:
OnIsLightDismissEnabledChanged();
}

void TeachingTip::IsOpenChangedToClose()
Expand Down

0 comments on commit c4c45e2

Please sign in to comment.