-
Notifications
You must be signed in to change notification settings - Fork 705
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
Hide NavigationViewItem Chevron if Children is empty #2759
Changes from 3 commits
1663ac7
7906e46
50577c7
98ff096
a56fa72
4750dce
69fc1bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -759,5 +759,70 @@ public void VerifyNavigationViewItemInFooterDoesNotCrash() | |
Verify.IsTrue(true); | ||
}); | ||
} | ||
|
||
[TestMethod] | ||
public void VerifyExpandCollapseChevronVisibility() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there no other tests that would verify the other branches of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chingucoding I haven't immediately found any other test (API/Interaction test) which we could fall back to here. Edit: Just noticed there is no public There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that are no tests that test collection changes in the MenuItems API. Would be best if we add those here or if we create a tracking issue to do that later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am adding the tests for the MenuItems API now. Will push it once it passes the tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{ | ||
NavigationView navView = null; | ||
NavigationViewItem parentItem = null; | ||
ObservableCollection<string> children = null; | ||
|
||
RunOnUIThread.Execute(() => | ||
{ | ||
navView = new NavigationView(); | ||
Content = navView; | ||
|
||
children = new ObservableCollection<string>(); | ||
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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also removed the FindVisualChildByName method. |
||
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; | ||
} | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#Fixed I think you need to revoke this listener in
UnhookEventsAndClearFields
too:microsoft-ui-xaml/dev/NavigationView/NavigationViewItem.cpp
Lines 918 to 928 in 50577c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I also need to rename the variable into
m_itemsSourceViewCollectionChangedRevoker
to be inline with the other revokers?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, yes that would be great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pushed a commit doing this.