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

标签 c# uwp uwp-xaml

我正在尝试为 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 自定义标题栏。结合Window.Current.SetTitleBar .总之,这些允许您在标题栏中使用自定义 XAML:

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

GitHub 上有一个很好的引用资源(由 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

关于c# - 如何自定义 UWP 页面的应用程序标题栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42042856/

相关文章:

c# - 从 UWP BackgroundTask 调用 MediaCapture.InitializeAsync

c# - 通过 Entity Framework BeginTransaction

c# - 泛型方法正在拾取基类的类型

c# - 如何更改 Windows Phone 中同一个 ListBox 中另一个对象的可见性?

c# - UWP XAML 和 C# - x :Bind on a DataTemplate inside a ResourceDictionary

c# - 更改窗口大小 UWP 时更改控件大小布局

C# 循环扫描二维数组的顶部、底部、左侧、右侧元素

c# - [c#]如何指定/GS,选项给c#应用程序?

javascript - UWP:如何访问应用程序数据

xaml - 如何向 UWP 中的 MenuFlyout 添加图标?