0

只需快速澄清一下 .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 函数中引用 xaml 元素作为参数?

这基于以下提供的示例(仅适用于 .cs):

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

4

2 回答 2

0

从 1.0 版本开始,这是首选方式。 https://docs.microsoft.com/en-us/windows/winui/api/microsoft.ui.xaml.window.settitlebar?view=winui-3.0

<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();
}

于 2022-01-27T00:52:01.750 回答
0

从 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>
于 2021-09-18T04:23:25.137 回答