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 badges1 Answer
Reset to default 1It 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
版权声明:本文标题:c# - WinUI 3 Titlebar and Navbar customization - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745030481a2638463.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论