简体   繁体   中英

How do I get the Frame to collapse and expand when PaneDisplayMode is LeftCompact?

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>

I'd like it to behave the same as when PaneDisplayMode is Left.

In a style of NavigationView , you could set the DisplayMode property of RootSplitView which is the name of a SplitView in NavigationView to CompactInline to implement the operation.

Please check the following code:

  1. Open the Document Outline panel, find and right-click your NavigationView navMenu > Edit Template > Edit a Copy . Then a default style of NavigationView will be copied to your Page.Resource tag and applied to your NavigationView control.

  2. In the style, find a VisualState whose name is Compact and add the following code:

     <VisualState.Setters> <Setter Target="RootSplitView.DisplayMode" Value="CompactInline" /> </VisualState.Setters>
  3. Build your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM