我可以确定一个UWP应用程序的标题栏外观的方式



我想给标题栏的外观和感觉的风格的应用程序。我使用XAML与c#编写这个UWP应用程序。

你可以这样做(通常在应用启动时):

var view = ApplicationView.GetForCurrentView();
view.TitleBar.BackgroundColor = ;
view.TitleBar.ForegroundColor = ;
view.TitleBar.ButtonBackgroundColor = ;
view.TitleBar.ButtonForegroundColor = ;
view.TitleBar.ButtonHoverBackgroundColor = Colors.Green;
view.TitleBar.ButtonHoverForegroundColor = Colors.White;
view.TitleBar.ButtonPressedBackgroundColor = ;
view.TitleBar.ButtonPressedForegroundColor = ;
view.TitleBar.ButtonInactiveBackgroundColor = ;
view.TitleBar.ButtonInactiveForegroundColor = ;
view.TitleBar.InactiveBackgroundColor = ;
view.TitleBar.InactiveForegroundColor = ;
<<p> 额外奖金/strong>如果你想将应用的UI扩展到TitleBar,这也是可能的。这篇博文有一个很好的例子,下面是总结:
CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
coreTitleBar.ExtendViewIntoTitleBar = true;

Lance McCarthy的回答只适用于桌面。
他的代码将在移动设备上运行,没有异常,但实际上不会改变状态栏,所以你不会看到任何影响。对于移动设备,你需要从nuget中选择"Windows Mobile Extensions For the UWP",然后你也可以改变手机上的状态栏:

if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
{
   var statusBar = StatusBar.GetForCurrentView();
   if (statusBar != null)
   {
      statusBar.BackgroundColor = Color.FromArgb(255, 81, 81, 81); // light gray color
   }
}

最新更新