【问题标题】:Why does overriding ApplicationPageBackgroundThemeBrush not work?为什么覆盖 ApplicationPageBackgroundThemeBrush 不起作用?
【发布时间】:2013-08-22 10:14:13
【问题描述】:

我正在尝试为我的 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>

【问题讨论】:

    标签: xaml windows-8 windows-runtime


    【解决方案1】:

    这两个画笔似乎只被 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。

    但实际上,使用这些画笔几乎没有什么好处,我认为最好将面板背景设置为所需的。

    【讨论】:

    • 谢谢你,微软似乎没有让默认模板特别有用,比如这个,进度条也默认为粉红色!
    猜你喜欢
    • 2018-07-06
    • 2019-12-07
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 2020-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多