diff --git a/dev/NavigationView/NavigationViewItem.cpp b/dev/NavigationView/NavigationViewItem.cpp index 0b3946bd0c..a2d2ba7b67 100644 --- a/dev/NavigationView/NavigationViewItem.cpp +++ b/dev/NavigationView/NavigationViewItem.cpp @@ -231,10 +231,12 @@ void NavigationViewItem::UpdateNavigationViewItemToolTip() void NavigationViewItem::SuggestedToolTipChanged(winrt::IInspectable const& newContent) { auto potentialString = newContent.try_as(); - const bool stringableToolTip = (potentialString && potentialString.Type() == winrt::PropertyType::String); + const bool validStringableToolTip = potentialString + && potentialString.Type() == winrt::PropertyType::String + && !potentialString.GetString().empty(); winrt::IInspectable newToolTipContent{ nullptr }; - if (stringableToolTip) + if (validStringableToolTip) { newToolTipContent = newContent; } diff --git a/dev/NavigationView/NavigationView_ApiTests/NavigationViewTests.cs b/dev/NavigationView/NavigationView_ApiTests/NavigationViewTests.cs index e4fdeb6dbf..44f0f01fa8 100644 --- a/dev/NavigationView/NavigationView_ApiTests/NavigationViewTests.cs +++ b/dev/NavigationView/NavigationView_ApiTests/NavigationViewTests.cs @@ -1091,5 +1091,113 @@ public void VerifyHierarchicalNavigationTopModeMenuItemsSourceDoesNotCrash() Content.UpdateLayout(); }); } + + [TestMethod] + public void VerifyNavigationViewItemToolTipCreation() + { + if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone5)) + { + Log.Warning("On RS4 and earlier the test needs to be modified slightly."); + return; + } + + RunOnUIThread.Execute(() => + { + var navView = new NavigationView(); + + // Item with null content + var menuItem1 = new NavigationViewItem(); + + // Item with empty string as content + var menuItem2 = new NavigationViewItem(); + menuItem2.Content = ""; + + // Item with null content and custom tooltip + var menuItem3 = new NavigationViewItem(); + ToolTipService.SetToolTip(menuItem3, "Custom tooltip"); + + // Item with non-empty string content + var menuItem4 = new NavigationViewItem(); + menuItem4.Content = "Item 4"; + + navView.MenuItems.Add(menuItem1); + navView.MenuItems.Add(menuItem2); + navView.MenuItems.Add(menuItem3); + navView.MenuItems.Add(menuItem4); + + // Use a pane configuration where tooltips are shown. + navView.PaneDisplayMode = NavigationViewPaneDisplayMode.Left; + navView.IsPaneOpen = false; + + Content = navView; + navView.UpdateLayout(); + + Verify.AreEqual(null, ToolTipService.GetToolTip(menuItem1), "Item 1's tooltip should have been [null]."); + Verify.AreEqual(null, ToolTipService.GetToolTip(menuItem2), "Item 2's tooltip should have been [null]."); + Verify.AreEqual("Custom tooltip", ToolTipService.GetToolTip(menuItem3), "Item 3's tooltip should have been \"Custom tooltip\"."); + Verify.AreEqual("Item 4", ToolTipService.GetToolTip(menuItem4), "Item 4's tooltip should have been \"Item 4\"."); + }); + } + + [TestMethod] + public void VerifyNavigationViewItemToolTipPaneDisplayMode() + { + if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone5)) + { + Log.Warning("On RS4 and earlier the test needs to be modified slightly."); + return; + } + + RunOnUIThread.Execute(() => + { + var navView = new NavigationView(); + + // Item with non-empty string content using in-built tooltip + var menuItem1 = new NavigationViewItem(); + menuItem1.Content = "Item 1"; + + // Item with custom tooltip + var menuItem2 = new NavigationViewItem(); + menuItem2.Content = "Item 2"; + ToolTipService.SetToolTip(menuItem2, "Custom tooltip"); + + navView.MenuItems.Add(menuItem1); + navView.MenuItems.Add(menuItem2); + + Content = navView; + + SetPaneConfigAndVerifyToolTips(NavigationViewPaneDisplayMode.Left, false, "Item 1", "Custom tooltip"); + SetPaneConfigAndVerifyToolTips(NavigationViewPaneDisplayMode.Left, true, null, "Custom tooltip"); + + SetPaneConfigAndVerifyToolTips(NavigationViewPaneDisplayMode.LeftCompact, false, "Item 1", "Custom tooltip"); + SetPaneConfigAndVerifyToolTips(NavigationViewPaneDisplayMode.LeftCompact, true, null, "Custom tooltip"); + + // Show tooltips again + SetPaneConfigAndVerifyToolTips(NavigationViewPaneDisplayMode.Left, false, "Item 1", "Custom tooltip"); + + SetPaneConfigAndVerifyToolTips(NavigationViewPaneDisplayMode.LeftMinimal, true, null, "Custom tooltip"); + + // Show tooltips again + SetPaneConfigAndVerifyToolTips(NavigationViewPaneDisplayMode.Left, false, "Item 1", "Custom tooltip"); + + SetPaneConfigAndVerifyToolTips(NavigationViewPaneDisplayMode.Top, false, null, "Custom tooltip"); + + // Show tooltips again + SetPaneConfigAndVerifyToolTips(NavigationViewPaneDisplayMode.Left, false, "Item 1", "Custom tooltip"); + + SetPaneConfigAndVerifyToolTips(NavigationViewPaneDisplayMode.Top, true, null, "Custom tooltip"); + + void SetPaneConfigAndVerifyToolTips(NavigationViewPaneDisplayMode paneDisplayMode, bool isPaneOpen, string expectedDefaultToolTip, string expectedCustomToolTip) + { + Log.Comment($"Verifying tooltips with PaneDisplayMode=[{paneDisplayMode}] and IsPaneOpen=[{isPaneOpen}]"); + navView.PaneDisplayMode = paneDisplayMode; + navView.IsPaneOpen = isPaneOpen; + Content.UpdateLayout(); + + Verify.AreEqual(expectedDefaultToolTip, ToolTipService.GetToolTip(menuItem1), $"Item 1's tooltip should have been \"{expectedDefaultToolTip ?? "null"}\"."); + Verify.AreEqual(expectedCustomToolTip, ToolTipService.GetToolTip(menuItem2), $"Item 2's tooltip should have been {expectedCustomToolTip}."); + } + }); + } } } \ No newline at end of file