When I set the PaneDisplayMode to LeftCompact, the NavigationPane overlaps on the frame. I'd like it to behave the same as when PaneDisplayMode is Left. Setting it to LeftCompact or LeftMinimal causes the Navigation flyout to overlap with the Frame. But Left causes the Frame to expand when the Navigation menu collapses, like it's supposed to. I'd like to get LeftCompact to do the same thing.
<Page
x:Class="TestApp.NavShell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:winui="using:Microsoft.UI.Xaml.Controls"
xmlns:wctoolkit="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:local="using:TestApp"
KeyDown="NavShell_KeyDown"
mc:Ignorable="d"
Background= "#FF474747">
<!--"{ThemeResource ApplicationPageBackgroundThemeBrush} -->
<Page.Resources>
</Page.Resources>
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="*"/>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<!--<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="50"/>
</Grid.ColumnDefinitions>-->
<winui:MenuBar x:Name="MainMenu" Grid.Row="0">
<winui:MenuBarItem Title="File">
<MenuFlyoutItem x:Name="ImportMI" Text="Import Things" >
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="I"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
<MenuFlyoutItem x:Name="ExportMI" Text="Export Things">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="E"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
<MenuFlyoutSeparator />
<MenuFlyoutItem x:Name="ExitMI" Text="Exit">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Windows" Key="X"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
</winui:MenuBarItem>
<winui:MenuBarItem Title="Edit">
<MenuFlyoutSeparator />
<MenuFlyoutItem x:Name="CutMI" Text="Cut" >
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="X"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
<MenuFlyoutItem x:Name="CopyMI" Text="Copy" >
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="C"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
<MenuFlyoutItem x:Name="PasteMI" Text="Paste" >
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="V"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
</winui:MenuBarItem>
<winui:MenuBarItem Title="Help">
<MenuFlyoutItem x:Name="HelpAboutMI" Text="About">
</MenuFlyoutItem>
</winui:MenuBarItem>
</winui:MenuBar>
<winui:NavigationView x:Name="navMenu" IsBackEnabled="True" IsBackButtonVisible="Collapsed" PaneDisplayMode="LeftCompact"
IsSettingsVisible="True" SelectionChanged="navMenu_SelectionChanged" Header="My Test App"
AlwaysShowHeader="True" PaneTitle="Test App" ExpandedModeThresholdWidth="100"
SelectionFollowsFocus="Enabled" IsTabStop="False" Grid.Row="1">
<winui:NavigationView.MenuItems>
<winui:NavigationViewItem Icon="Home" Content="Things">
<winui:NavigationViewItem.MenuItems>
<winui:NavigationViewItem Icon="Document" Content="More Things">
<winui:NavigationViewItem.MenuItems>
<winui:NavigationViewItem>
<winui:NavigationViewItem.Content>
<winui:BitmapIconSource UriSource="NewFolder\Images\Things.png" />
</winui:NavigationViewItem.Content>
</winui:NavigationViewItem>
</winui:NavigationViewItem.MenuItems>
</winui:NavigationViewItem>
</winui:NavigationViewItem.MenuItems>
</winui:NavigationViewItem>
<winui:NavigationViewItem Icon="Document" Content="Other Things">
</winui:NavigationViewItem>
</winui:NavigationView.MenuItems>
<winui:NavigationView.PaneCustomContent>
<HyperlinkButton x:Name="PaneHyperlink" Content="More info" Margin="12,0" Visibility="Collapsed" />
</winui:NavigationView.PaneCustomContent>
<winui:NavigationView.PaneFooter>
<StackPanel x:Name="SettingsFooter" Orientation="Vertical" Visibility="Collapsed">
<winui:NavigationViewItem Icon="Setting" AutomationProperties.Name="settings" />
</StackPanel>
</winui:NavigationView.PaneFooter>
<Frame x:Name="NavContent" Margin="0, 0, 0, 0">
</Frame>
</winui:NavigationView>
</Grid>
</Page>
In a style of
NavigationView
, you could set theDisplayMode
property ofRootSplitView
which is the name of aSplitView
inNavigationView
toCompactInline
to implement the operation.Please check the following code:
Open the Document Outline panel, find and right-click your NavigationView
navMenu
> Edit Template > Edit a Copy. Then a default style ofNavigationView
will be copied to yourPage.Resource
tag and applied to yourNavigationView
control.In the style, find a
VisualState
whose name isCompact
and add the following code:Build your project.