c# - 更改 Metro 风格应用程序的背景颜色无效

标签 c# xaml windows-8 visual-studio-2012 microsoft-metro

我正在尝试将我在 visual studio (XAML) 中的应用程序的背景颜色更改为白色(或 ApplicationPageBackgroundTheme/或其他名称),但它不起作用。当我调试时,它只显示黑色背景。

当我转到“设备” Pane 并将默认颜色主题选择为“浅色”时,它会使屏幕上的所有内容变白,甚至包括文本和背景。

当我在 xaml 中更改颜色背景时,在运行时它会变回黑色!

我搜索过,但没有找到任何信息。这是一个已知的错误?这以前从未发生过。我正在使用 Visual Studio 2012 Ultimate。

<Page
    x:Class="hjgjhgjg.MainPage"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:hjgjhgjh"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" Background="White">

    <Grid Style="{StaticResource LayoutRootStyle}" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="140" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="False" Style="{StaticResource BackButtonStyle}" />
            <TextBlock x:Name="pageTitle" Grid.Column="1" Text="gfdgfdg" Style="{StaticResource PageHeaderTextStyle}" />
        </Grid>
    </Grid>
</Page>

enter image description here

最佳答案

如果没有更多的应用程序/样式,很难确切地知道发生了什么,但是更改主题的一种简单方法是使用 Application 对象的 RequestedTheme property .

例如,在 App.xaml 中,将 RequestedTheme="Light" 设置为 Application 元素的属性:

<Application
    x:Class="App1.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    RequestedTheme="Light">

这很有用,因为 Light 主题会影响所有页面并自动更改文本/按钮/等。如果您只将背景色设为白色,则将其设为黑色而不是一切都是白色。

本演练介绍了这一点以及如何使用您自己的自定义样式覆盖默认样式:

顺便说一句,“设备” Pane 不会更改应用程序设置,但会在设计 View 中模拟应用程序在各种设备功能/设置(屏幕、主题等)下的显示方式。因此,虽然它在设计器中看起来像是一个主题,它将恢复为系统/XAML/代码在您实际运行时产生的任何结果。

关于c# - 更改 Metro 风格应用程序的背景颜色无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13920397/

相关文章:

c# - Windows.UI.Xaml.dll 中的应用程序内部异常

java - 在路径中找不到 firefox 二进制文件

windows-8 - 在 Windows 8 Metro 中隐藏虚拟键盘

windows-8 - GestureRecognizer 中的触摸点数量

C# - 您可以在通用列表中单独循环遍历类型吗?

c# - 在 Canvas 中动态添加 XAML 中的图像

c# - 缓慢读取数百个文件

wpf - 在具有设计预览功能的 ResourceDictionary 中包含 XAML 图像

c# - WCF CustomToken 错误 "security token with the ' Basic 的附件模式必须签名。”

c# - 如何阻止方法递归调用自己?