I am writing a UWP app that has a NavigationView
containing NavigationViewItemHeader
s:
<NavigationView.MenuItems>
<NavigationViewItem Content="Home" Tag="home">
<NavigationViewItem.Icon>
<FontIcon Glyph=""/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItemSeparator/>
<NavigationViewItemHeader x:Name="ThemesHeading" Content="Themes"/>
<NavigationViewItem Content="Themes" Tag="themes">
<NavigationViewItem.Icon>
<FontIcon Glyph=""/>
</NavigationViewItem.Icon>
</NavigationViewItem>
(and so on)
However when I collapse the view, the headers get clipped:
What should I do to prevent this?
Solution 1
Increase the left margin of item headers:
<NavigationViewItemHeader Content="Themes" Margin="33,0,0,0"/>
...
<NavigationViewItemHeader Content="Builds" Margin="33,0,0,0"/>
Solution 2
Disable compact and expanded display mode of the NavigationView
by setting the CompactModeThresholdWidth
and ExpandedModeThresholdWidth
to some big number:
<NavigationView CompactModeThresholdWidth="100000" ExpandedModeThresholdWidth="100000">
Solution 3
Bind the Visibility
property of item headers to the IsPaneOpen
property of the NavigationView
as André B suggested, only use x:Bind
instead of Binding
since it doesn't need a converter:
<NavigationView Name="MyNavigationView">
...
<NavigationViewItemHeader Content="Themes" Visibility="{x:Bind MyNavigationView.IsPaneOpen, Mode=OneWay}"/>
...
<NavigationViewItemHeader Content="Builds" Visibility="{x:Bind MyNavigationView.IsPaneOpen, Mode=OneWay}"/>
...
</NavigationView>