diff --git a/dev/NavigationView/NavigationView_ApiTests/NavigationViewTests.cs b/dev/NavigationView/NavigationView_ApiTests/NavigationViewTests.cs index a3f1c295c5..4cd40b4529 100644 --- a/dev/NavigationView/NavigationView_ApiTests/NavigationViewTests.cs +++ b/dev/NavigationView/NavigationView_ApiTests/NavigationViewTests.cs @@ -759,5 +759,70 @@ public void VerifyNavigationViewItemInFooterDoesNotCrash() Verify.IsTrue(true); }); } + + [TestMethod] + public void VerifyExpandCollapseChevronVisibility() + { + NavigationView navView = null; + NavigationViewItem parentItem = null; + ObservableCollection children = null; + + RunOnUIThread.Execute(() => + { + navView = new NavigationView(); + Content = navView; + + children = new ObservableCollection(); + parentItem = new NavigationViewItem() { Content = "ParentItem", MenuItemsSource = children }; + + navView.MenuItems.Add(parentItem); + + navView.Width = 1008; // forces the control into Expanded mode so that the menu renders + Content.UpdateLayout(); + + UIElement chevronUIElement = (UIElement)FindVisualChildByName(parentItem, "ExpandCollapseChevron"); + Verify.IsTrue(chevronUIElement.Visibility == Visibility.Collapsed, "chevron should have been collapsed as NavViewItem has no children"); + + // Add a child to our NavigationView parentItem. This should make the chevron visible. + children.Add("Undo"); + Content.UpdateLayout(); + + Verify.IsTrue(chevronUIElement.Visibility == Visibility.Visible, "chevron should have been visible as NavViewItem now has children"); + + // Remove all children from our NavigationView parentItem. This should collapse the chevron + children.Clear(); + Content.UpdateLayout(); + + Verify.IsTrue(chevronUIElement.Visibility == Visibility.Collapsed, "chevron should have been collapsed as NavViewItem no longer has children"); + }); + } + + private static DependencyObject FindVisualChildByName(FrameworkElement parent, string name) + { + if (parent.Name == name) + { + return parent; + } + + int childrenCount = VisualTreeHelper.GetChildrenCount(parent); + + for (int i = 0; i < childrenCount; i++) + { + FrameworkElement childAsFE = VisualTreeHelper.GetChild(parent, i) as FrameworkElement; + + if (childAsFE != null) + { + DependencyObject result = FindVisualChildByName(childAsFE, name); + + if (result != null) + { + return result; + } + } + } + + return null; + } + } } \ No newline at end of file