问题描述
我正在尝试将Visual Studio(XAML)中的应用程序的背景颜色更改为White(或ApplicationPageBackgroundTheme/或任何它所谓的名称),并且不起作用.当我调试时,它只会显示黑色背景.
I am trying to change the background color of my application in visual studio (XAML) to White (or, ApplicationPageBackgroundTheme / or whatever it's called) and it doesn't work. When I debug, it just shows a black background.
当我转到设备"窗格并将默认颜色主题选择为浅色"时,它将使屏幕上的所有内容变为白色,甚至包括文本和背景.
When I go to the Devices pane and select the default color theme to "Light", it makes everything on the screen white, even the text and the background.
当我在xaml中更改颜色的背景时,在运行时它将变回黑色!
When I change the background of the colors in xaml, at runtime it gets changed back to black!
我已经搜索过,但是没有找到任何信息.这是一个已知的错误?这从未发生过.我正在使用Visual Studio 2012 Ultimate.
I've searched, but haven't found any information. Is this a known bug? This has never happened before. I am using 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>
推荐答案
在没有更多应用程序/样式的情况下,很难确切知道发生了什么,但是更改主题的一种简单方法是使用Application
对象的 RequestedTheme属性.
Hard to know exactly what's going on without more of the app/styles, but an easy way to change theme is to use the Application
object's RequestedTheme property.
例如,在App.xaml中,将RequestedTheme="Light"
设置为Application元素的属性:
For example, in App.xaml, set RequestedTheme="Light"
as a property of the Application element:
<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主题随后将影响所有页面并自动更改文本/按钮/等.如果您只将背景色设为白色,则将其设为黑色,而不是将一切设为白色.
This can be helpful because the Light theme will then affect all pages and automatically changes text/buttons/etc. to black instead of everything being white if you only make the background color white.
本演练介绍了此方法以及如何使用您自己的自定义样式覆盖默认样式:
This walkthrough covers this and how to override default styles with your own custom ones:
顺便说一句,设备"窗格不会更改应用程序设置,但会在设计视图中模拟应用程序在各种设备功能/设置(屏幕,主题等)下的显示方式,因此在设计器中看起来像是一个主题,它将恢复为实际运行时系统/XAML/代码产生的结果.
BTW, the Device pane doesn't change app settings, but simulates in design view how the app would appear with various device features/settings (screen, theme, etc.) So while it may look like one theme in the designer, it's going to revert to whatever the system/XAML/code results in when you actually run it.
这篇关于更改Metro风格应用的背景颜色无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!