Search code examples
c#uwpclip

UWP - Prevent NavigationViewItemHeader from being clipped


I am writing a UWP app that has a NavigationView containing NavigationViewItemHeaders:

   <NavigationView.MenuItems>
        <NavigationViewItem Content="Home" Tag="home">
            <NavigationViewItem.Icon>
                <FontIcon Glyph="&#xE80F;"/>
            </NavigationViewItem.Icon>
        </NavigationViewItem>

        <NavigationViewItemSeparator/>
        <NavigationViewItemHeader x:Name="ThemesHeading" Content="Themes"/>

        <NavigationViewItem Content="Themes" Tag="themes">
            <NavigationViewItem.Icon>
                <FontIcon Glyph="&#xE771;"/>
            </NavigationViewItem.Icon>
        </NavigationViewItem>

(and so on)

However when I collapse the view, the headers get clipped:

What should I do to prevent this?


Solution

  • 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"/>
    

    enter image description here

    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">
    

    enter image description here

    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>
    

    enter image description here