只需快速澄清.setTitleBar()的使用情况。
MainWindow.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
MainWindow::ExtendsContentIntoTitleBar(true);
MainWindow::SetTitleBar(?);如何在SetTitleBar函数中引用xaml元素作为参数?
这是基于以下所提供的示例(仅适用于.cs):
发布于 2021-09-18 04:23:25
从项目团圆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>发布于 2022-01-27 00:52:01
在1.0版中,这是首选的方法。https://learn.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();
}
https://stackoverflow.com/questions/67588514
复制相似问题