Windows Universal App全屏按钮

Windowsapp store中的某些应用程序在Titlebar中的最小化,最大化和关闭按钮之外还有一个全屏按钮。 如果全屏处于活动状态,此按钮看起来类似于每个应用程序在标题栏中具有的退出全屏按钮。 这是一个系统控制,如果我可以在我的C#Universal App中使用它?

您必须使用Window.SetTitleBar方法来实现所需的行为。 因此,您需要完成以下几个步骤:

首先,启用视图以扩展到标题栏。 请注意,您只能设置标题栏的左侧部分。 最小化最大化关闭按钮仍然存在:

 CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true; 

设置完成后,使用UIElement调用Window.SetTitleBar方法:

 Window.Current.SetTitleBar(myTitleBar); 

myTitleBar位置如下:

                

可以在这里找到Marco Minerva的扩展指南(包括一个很好的XAML行为,可以更好地调整这个用例)。

我制作了一个FullScreenModeTitleBarBehavior (以及一个FullScreenModeTitle控件),它可能只是你想要的。

在此处输入图像描述

行为需要附加到您的Page ,它允许您指定TitleBar的前景色和背景色。 如果您需要更多颜色,可以简单地为行为添加更多属性。

它的工作方式是行为将ContentPage移动到FulScreenModeTitle控件,该控件基本上组成了一个自定义的TitleBar与移动的Content

 // Store the original main page content. var mainPageContent = _mainPage.Content; // Clear the content for now. _mainPage.Content = null; // Move the content of the main page to our title bar control. _customTitleBar.SetPageContent(mainPageContent); // Refill the content with our new title bar control. _mainPage.Content = _customTitleBar; 

您可以在GitHub中找到完整的源代码。 另请注意,此解决方案的灵感来自Microsoft的GitHub存储库中的此特定示例 。


到目前为止我发现的一些问题

您可能已经注意到我们的自定义全屏模式按钮最小化按钮之间存在差距 。 不幸的是你无法进一步减少它’因为系统保留了这么多空间(有关更多细节,请查看SystemOverlayRightInset )。 如果您将自定义按钮移近,则命中测试将失败,这使其无法点击。

此外,我发现如果您使用自定义按钮退出全屏,那么这三个系统按钮将无法正常运行,直到您双击TitleBar以最大化屏幕。 这可能是一个错误。 幸运的是,当屏幕处于全屏模式时, 最大化按钮将被退出全屏按钮取代,因此我们可以隐藏我们的自定义按钮并让系统处理退出。

它可以区分为3种类型的全屏模式1.进入和退出全屏模式。 2.响应全屏模式的变化。 3.以全屏模式启动。

您可以参考此URL https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/FullScreenMode

 var view = ApplicationView.GetForCurrentView(); if (view.IsFullScreenMode) { view.ExitFullScreenMode(); rootPage.NotifyUser("Exiting full screen mode", NotifyType.StatusMessage); // The SizeChanged event will be raised when the exit from full screen mode is complete. } else { if (view.TryEnterFullScreenMode()) { rootPage.NotifyUser("Entering full screen mode", NotifyType.StatusMessage); // The SizeChanged event will be raised when the entry to full screen mode is complete. } else { rootPage.NotifyUser("Failed to enter full screen mode", NotifyType.ErrorMessage); } }