如何自定义 UWP 页面的应用程序标题栏

How to customize the application title bar for a UWP page

我正在尝试为 UWP 页面设置页面的应用程序标题栏始终可见,并禁用恢复按钮,但我没有找到与此相关的任何内容。

我所能做的就是更改具有如下代码的应用程序标题栏的颜色

    public MainPage()
    {
        this.InitializeComponent();
        ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
        ApplicationView.GetForCurrentView().Title = "TEST";
        ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;
        titleBar.ForegroundColor = Color.FromArgb(1, 1, 1, 1);

    }

但这就是我所能做的...而且应用程序标题栏的标题表现得很奇怪,因为我将它设置为 "TEST" 但在 UI 上显示 "ProjectName-TEST" .

所以,你知道我如何自定义(设置应用程序栏标题,将其设置为始终可见,而不仅仅是当用户将光标移动到页面顶部并禁用恢复按钮时(就像我可以以 windows 形式))UWP 项目页面的应用程序标题栏?

目前无法禁用任何标题栏按钮(最小化、最大化等)。有some discussion about this on GitHub可以关注

除此限制外,您还可以使用 ExtendViewIntoTitleBar in combination with Window.Current.SetTitleBar 自定义标题栏。总之,这些允许您在标题栏中使用自定义 XAML:

CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
...
Window.Current.SetTitleBar(myTitleBar);

GitHub 上有一个很好的 go-to 资源(由 Microsoft 创建)显示您可以自定义的内容:Title bar sample

The sample shows the following techniques:

Customizing the colors in the standard system title bar.

Extending the view into the title bar, so you can draw a custom title bar.

Responding to changes in title bar states.

Drawing controls in the title bar (XAML only).

这里有一些关于自定义标题栏的其他好教程:

Easily manage the Title Bar in Windows 10 apps

[UWP]Take the control of your title bar