我尝试为我的 Windows 8 应用商店应用程序定义默认背景颜色,但尽管它在 XAML 编辑器和 Blend 中正确显示,但在 Windows 8 和 Windows RT 上运行时它会显示默认的黑色背景模拟器。
我基于“Split App”VS 2012 模板创建了一个全新的 Windows 8 应用程序,并修改了 App.xaml 以指定 ApplicationPageBackgroundThemeBrush 的新值。
这就是我的 App.xaml 的样子:
<Application
x:Class="App3.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App3"
xmlns:localData="using:App3.Data">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--
Styles that define common aspects of the platform look and feel
Required by Visual Studio project and item templates
-->
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!-- Application-specific resources -->
<x:String x:Key="AppName">App3</x:String>
<!-- Basic foreground and background colours -->
<SolidColorBrush x:Key="ApplicationPageBackgroundThemeBrush" Color="#FF3CA5DC"/>
<SolidColorBrush x:Key="ApplicationPageForegroundThemeBrush" Color="White"/>
</ResourceDictionary>
</Application.Resources>
最佳答案
看来这2个画笔只被StandardStyles.xaml中的少数样式使用,其中之一是
<Style x:Key="LayoutRootStyle" TargetType="Panel">
您可以将其应用到根面板。但您在 App.xaml 中的更改不会影响此样式。它仅影响此画笔的进一步使用,因此如果您想使用这些特定画笔,我会看到以下变体:
1)在 App.xml 中声明它们并进一步使用它,如下所示:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
2) 在 StadardStyles.xaml
下声明它们
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<!-- Style Goes Here -->
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
在这种情况下,所有 StandardStyles 都会受到影响,但您也应该在 Grid 中使用 LayoutRootStyle。
但实际上,使用这些画笔的 yield 非常小,因此我认为最好将面板背景设置为您需要的内容。
关于xaml - 为什么覆盖 ApplicationPageBackgroundThemeBrush 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15093651/