admin管理员组

文章数量:1410730

while learning winui3 i wanted to make a simple sample application such as microsoft teams

when i was trying to design i wanted to write the title name next to the navbar

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Border x:Name="AppTitleBar" Grid.Column="1" VerticalAlignment="Top">
            <TextBlock x:Name="AppTitle" Text="TitleName" VerticalAlignment="Top" Margin="0,8,0,0" />
        </Border>
        <NavigationView x:Name="nvSample">
            <NavigationView.MenuItems>
                <NavigationViewItem Icon="Play" Content="Menu Item1" Tag="SamplePage1" />
                <NavigationViewItem Icon="Save" Content="Menu Item2" Tag="SamplePage2" />
                <NavigationViewItem Icon="Refresh" Content="Menu Item3" Tag="SamplePage3" />
                <NavigationViewItem Icon="Download" Content="Menu Item4" Tag="SamplePage4" />
            </NavigationView.MenuItems>
            <Frame x:Name="contentFrame"/>
        </NavigationView>
    </Grid>

what i got

what i want im trying to do something like this picture and i dont understand how to do it please help

while learning winui3 i wanted to make a simple sample application such as microsoft teams

when i was trying to design i wanted to write the title name next to the navbar

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Border x:Name="AppTitleBar" Grid.Column="1" VerticalAlignment="Top">
            <TextBlock x:Name="AppTitle" Text="TitleName" VerticalAlignment="Top" Margin="0,8,0,0" />
        </Border>
        <NavigationView x:Name="nvSample">
            <NavigationView.MenuItems>
                <NavigationViewItem Icon="Play" Content="Menu Item1" Tag="SamplePage1" />
                <NavigationViewItem Icon="Save" Content="Menu Item2" Tag="SamplePage2" />
                <NavigationViewItem Icon="Refresh" Content="Menu Item3" Tag="SamplePage3" />
                <NavigationViewItem Icon="Download" Content="Menu Item4" Tag="SamplePage4" />
            </NavigationView.MenuItems>
            <Frame x:Name="contentFrame"/>
        </NavigationView>
    </Grid>

what i got

what i want im trying to do something like this picture and i dont understand how to do it please help

Share Improve this question edited Mar 5 at 7:09 Andrew KeepCoding 14.2k2 gold badges21 silver badges37 bronze badges asked Mar 4 at 20:28 Muhammed Yusuf ParlakMuhammed Yusuf Parlak 231 silver badge4 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

It seems that the WinUI 3 Gallery app is very close to what you are trying to achieve.

Based on your code, the following should do:

MainWindow.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Border x:Name="AppTitleBar"
        Grid.Row="0"
        Grid.Column="1"
        Height="{Binding ElementName=nvSample, Path=CompactPaneLength}"
        Margin="48,0,0,0"
        VerticalAlignment="Stretch">
        <StackPanel
            VerticalAlignment="Stretch"
            Orientation="Horizontal">
            <Image
                Width="18"
                VerticalAlignment="Center"
                Source="ms-appx:///Assets/StoreLogo.png" />
            <TextBlock x:Name="AppTitle"
                Margin="12,0,0,0"
                VerticalAlignment="Center"
                Style="{StaticResource CaptionTextBlockStyle}"
                Text="TitleName" />
        </StackPanel>
    </Border>
    <NavigationView x:Name="nvSample"
        Grid.Row="0"
        Grid.RowSpan="2"
        Grid.Column="1"
        Canvas.ZIndex="0"
        IsTitleBarAutoPaddingEnabled="True">
        <NavigationView.Resources>
            <!--  This top margin is the height of the custom titleBar  -->
            <Thickness x:Key="NavigationViewContentMargin">0,48,0,0</Thickness>
            <Thickness x:Key="NavigationViewMinimalContentMargin">0,48,0,0</Thickness>
            <Thickness x:Key="NavigationViewContentGridBorderThickness">1,1,0,0</Thickness>
            <!--  This is the rounded corner on the Top left of the L Pattern  -->
            <CornerRadius x:Key="NavigationViewContentGridCornerRadius">8,0,0,0</CornerRadius>
        </NavigationView.Resources>
        <NavigationView.MenuItems>
...

MainWindow.xaml.cs

public MainWindow()
{
    InitializeComponent();
    ExtendsContentIntoTitleBar = true;
    AppWindow.TitleBar.PreferredHeightOption = Microsoft.UI.Windowing.TitleBarHeightOption.Tall;
    SetTitleBar(AppTitleBar);
}

Just in case, you can learn more about the following resources in the generic.xaml file.

  • NavigationViewContentMargin
  • NavigationViewMinimalContentMargin
  • NavigationViewContentGridBorderThickness

本文标签: cWinUI 3 Titlebar and Navbar customizationStack Overflow