Skip to content

Commit

Permalink
Add fix for NavViewItems in footer crashing (#2395)
Browse files Browse the repository at this point in the history
* Add fix for NavViewItems in footer crashing

* CR feedback
  • Loading branch information
marcelwgn authored May 6, 2020
1 parent 1785888 commit a34eaf2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
8 changes: 5 additions & 3 deletions dev/NavigationView/NavigationViewItemPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ void NavigationViewItemPresenter::OnApplyTemplate()
m_expandCollapseChevron.set(expandCollapseChevron);
m_expandCollapseChevronTappedToken = expandCollapseChevron.Tapped({ navigationViewItem, &NavigationViewItem::OnExpandCollapseChevronTapped });
}

navigationViewItem->UpdateVisualStateNoTransition();


// We probably switched displaymode, so restore width now, otherwise the next time we will restore is when the CompactPaneLength changes
if (navigationViewItem->GetNavigationView().PaneDisplayMode() != winrt::NavigationViewPaneDisplayMode::Top)
if(auto&& navigationView = navigationViewItem->GetNavigationView())
{
UpdateCompactPaneLength(m_compactPaneLengthValue, true);
if (navigationView.PaneDisplayMode() != winrt::NavigationViewPaneDisplayMode::Top)
{
UpdateCompactPaneLength(m_compactPaneLengthValue, true);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using MUXControlsTestApp.Utilities;
Expand Down Expand Up @@ -685,5 +685,26 @@ public void VerifySelectedItemIsNullWhenNoItemIsSelected()
Verify.AreEqual(null, navView.SelectedItem, "SelectedItem should have been [null] as no item is selected");
});
}

[TestMethod]
public void VerifyNavigationViewItemInFooterDoesNotCrash()
{
RunOnUIThread.Execute(() =>
{
var navView = new NavigationView();

Content = navView;

var navViewItem = new NavigationViewItem() { Content = "Footer item" };

navView.PaneFooter = navViewItem;

navView.Width = 1008; // forces the control into Expanded mode so that the menu renders
Content.UpdateLayout();

// If we don't get here, app has crashed. This verify is just making sure code got run
Verify.IsTrue(true);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<AutoSuggestBox QueryIcon="Find" AutomationProperties.Name="PaneAutoSuggestBox"/>
</muxc:NavigationView.AutoSuggestBox>

<muxc:NavigationView.PaneFooter>
<muxc:NavigationViewItem Content="Footer item"/>
</muxc:NavigationView.PaneFooter>

<muxc:NavigationView.Content>
<StackPanel Padding="50" Orientation="Horizontal">
Expand Down

0 comments on commit a34eaf2

Please sign in to comment.