UWP 设计自定义标题栏

问题描述

我在 WPF 中设计了这个标题栏,但在 UWP 中我不知道如何做到这一点。

enter image description here

我看到几个链接,但没有一个不适合我:

  1. UWP quick tip: custom titlebar [ github : BlogTitleBar ]​​i>
  2. Title bar customization [微软]
  3. How to add a new button in title bar next the minimize button in UWP? [ stackoverflow ]​​i>
  4. Customize Title Bar & Add Full Screen Button in UWP

我想隐藏当前的标题栏并创建一个新的,我觉得这个方法更简单,我有能力做任何改变;在 WPF 中就是这种情况。

解决方法

您将 CoreApplicationViewTitleBar.ExtendViewIntoTitleBar 属性设置为 true,然后使用视图中的元素创建您自己的自定义标题栏,如第二个链接的 docs 中所述。

当您选择完全自定义标题栏时,您应用的客户区将扩展为覆盖整个窗口,包括标题栏区域。您负责整个窗口的绘制和输入处理,除了覆盖在应用画布上的标题按钮。

// using Windows.ApplicationModel.Core;

// Hide default title bar.
var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
coreTitleBar.ExtendViewIntoTitleBar = true;