[英]WINUI3 - Customize TitleBar
只需快速澄清一下 .setTitleBar() 的用法。
主窗口.xaml
<Window
x:Class="Wrath.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Wrath"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<!-- ... -->
<TextBlock x:Name="CustomTitleBar">Custom title text</TextBlock>
<!-- ... -->
</Grid>
</Window>
主窗口.xaml.cpp
MainWindow::ExtendsContentIntoTitleBar(true);
MainWindow::SetTitleBar(?);
如何在 SetTitleBar function 中引用 xaml 元素作為參數?
這基於以下提供的示例(僅 for.cs):
從 project reunion 0.8 開始,我已經能夠成功設置標題欄如下:
在您的 MainWindow.xaml.cpp 文件中:
MainWindow::MainWindow()
{
InitializeComponent();
this->ExtendsContentIntoTitleBar(true);
this->SetTitleBar(AppTitleBar());
}
在您的 MainWindow.xaml 文件中的某處:
<Grid x:Name="AppTitleBar">
... titlebar code goes here
</Grid>
從 1.0 版本開始,這是首選方式。 https://docs.microsoft.com/en-us/windows/winui/api/microsoft.ui.xaml.window.settitlebar?view=winui-3.
<Window...> <Grid> <.--..: --> <TextBlock x.Name="CustomTitleBar">Custom title text</TextBlock> <.--... --> </Grid> </Window>
和
private MainWindow m_window; protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args) { m_window = new MainWindow(); m_window.ExtendsContentIntoTitleBar = true; m_window.SetTitleBar(m_window.CustomTitleBar); m_window.Activate(); }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.