简体   繁体   English

WINUI3 - 自定义标题栏

[英]WINUI3 - Customize TitleBar

Just a quick clarification needed regarding.setTitleBar() usage.只需快速澄清一下 .setTitleBar() 的用法。

MainWindow.xaml主窗口.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>

MainWindow.xaml.cpp主窗口.xaml.cpp

MainWindow::ExtendsContentIntoTitleBar(true);
MainWindow::SetTitleBar(?);

How do I reference the xaml element as argument in the SetTitleBar function?如何在 SetTitleBar function 中引用 xaml 元素作为参数?

This is based on the example (only for.cs) provided from:这基于以下提供的示例(仅 for.cs):

https://docs.microsoft.com/en-us/windows/winui/api/microsoft.ui.xaml.window.settitlebar?view=winui-3.0 https://docs.microsoft.com/en-us/windows/winui/api/microsoft.ui.xaml.window.settitlebar?view=winui-3.

As of project reunion 0.8, I have been able to successfully set the titlebar as follows:从 project reunion 0.8 开始,我已经能够成功设置标题栏如下:

In your MainWindow.xaml.cpp file:在您的 MainWindow.xaml.cpp 文件中:

MainWindow::MainWindow()
{
    InitializeComponent();
    this->ExtendsContentIntoTitleBar(true);
    this->SetTitleBar(AppTitleBar());        
}

In your MainWindow.xaml file somewhere:在您的 MainWindow.xaml 文件中的某处:

<Grid x:Name="AppTitleBar">
    ... titlebar code goes here        
</Grid>

As of the 1.0 release this is the preferred way.从 1.0 版本开始,这是首选方式。 https://docs.microsoft.com/en-us/windows/winui/api/microsoft.ui.xaml.window.settitlebar?view=winui-3.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>

with

 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.

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