效果
Winui3 Gallery中导航栏左侧和上方标题栏背景颜色相同,上方标题栏可以自定义:
代码:
App.xaml
<StaticResource x:Key="WindowCaptionBackground" ResourceKey="SystemControlTransparentBrush" />
<StaticResource x:Key="WindowCaptionBackgroundDisabled" ResourceKey="SystemControlTransparentBrush" />
将右上角按键的背景色设置为透明。如果不设置,会导致程序右上方三个按钮不可见或者跟title中其他元素颜色不同,或者不可点击等问题。
MainWindow.xaml
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border x:Name="AppTitleBar" Height="32" VerticalAlignment="Top" Grid.Row="0">
<StackPanel Orientation="Horizontal">
<Image Source="Images/fileManager.png"
HorizontalAlignment="Left"
Width="16" Height="16"
Margin="20,0"/>
<TextBlock x:Name="AppTitleTextBlock" Text="SoftWare"
TextWrapping="NoWrap"
Style="{StaticResource CaptionTextBlockStyle}"
VerticalAlignment="Center" Margin="0" />
</StackPanel>
</Border>
<Frame x:Name="frame" Grid.Row="1"></Frame>
</Grid>
如果代码全写在MainWindow中,也可以不设置Grid.Row,直接把Border
标签写上,然后再写其它前端元素即可,因为我把代码全写在了page界面中,需要从MainWindow跳转,如果不定义两行,frame.navigate指代的是整个页面,会导致title不可见。
MainWindow.xaml.cs
public MainWindow()
{
this.InitializeComponent();
ExtendsContentIntoTitleBar = true;
SetTitleBar(AppTitleBar);
frame.Navigate(typeof(MainPage), null);
}