如何自定义 UWP 页面的应用程序标题栏 [英] How to customize the application title bar for a UWP page
问题描述
我正在尝试为 UWP 页面设置始终可见的页面的应用程序标题栏,并禁用恢复按钮,但我没有找到与此相关的任何内容.
I am trying to set the application title bar of a page visibile all the time for a UWP page and also disable the restore button, but I am not finding anything related to this.
我所能做的就是更改具有如下代码的应用程序标题栏的颜色
All i could do was to change the color of the application title bar having a code like below
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".
but that was all i could do... Also the title of the application title bar was acting strange since i set it to "TEST" but on UI was showing "ProjectName-TEST".
那么,您知道我如何自定义(设置应用程序栏标题,将其设置为始终可见,而不仅仅是在用户将光标移动到页面顶部并禁用恢复按钮时(就像我可以拥有它一样)在 Windows 窗体中)) UWP 项目页面的应用程序标题栏?
So, do you know how could I customize (set the application bar title, set it as visible all the time not only when the user moves the cursor on top of the page and disable the restore button (like i could have it in windows forms)) the application title bar of a page for an UWP project ?
推荐答案
目前无法禁用任何标题栏按钮(最小化、最大化等).GitHub 上有一些关于此的讨论,您可以关注.
Currently it's not possible to disable any of the title bar buttons (minimize, maximize, etc). There's some discussion about this on GitHub which you can follow.
除此限制外,您还可以使用 ExtendViewIntoTitleBar 结合 Window.Current.SetTitleBar.总之,这些允许您在标题栏中使用自定义 XAML:
Apart from this limitation, you can customize the title bar quite heavily by using ExtendViewIntoTitleBar in combination with Window.Current.SetTitleBar. In summary these allow you to use custom XAML in title bar:
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
...
Window.Current.SetTitleBar(myTitleBar);
GitHub(由 Microsoft 创建)上有一个很好的参考资源,其中显示了您可以自定义的内容:标题栏示例
There's a good go-to resource on GitHub (created by Microsoft) which show what you can customize: 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.
标题栏中的绘图控件(仅限 XAML).
Drawing controls in the title bar (XAML only).
这里有一些关于自定义标题栏的其他很好的教程:
Here's couple other good tutorials about customizing the title bar:
这篇关于如何自定义 UWP 页面的应用程序标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!