How to customize the application title bar for a UWP page

拈花ヽ惹草 提交于 2019-12-14 03:42:15

问题


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

    }

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".

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 ?


回答1:


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.

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

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.

Drawing controls in the title bar (XAML only).

Here's couple other good tutorials about customizing the title bar:

Easily manage the Title Bar in Windows 10 apps

[UWP]Take the control of your title bar



来源:https://stackoverflow.com/questions/42042856/how-to-customize-the-application-title-bar-for-a-uwp-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!