问题
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.
When I change the background of the colors in xaml, at runtime it gets changed back to black!
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>

回答1:
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.
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">
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:
- Part 1: Create a "Hello, world" app (Windows Store apps using C#/VB and 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.
回答2:
If I remember correctly, you can check in the manifest in the first tab. There should be an option for ya there.
回答3:
The background color of the page won't be visible, because the root Grid is opaque and have it's color set to black by default, what you can do is set the color of the Grid to a transparent one, or apply the white color to the Grid, as i see you've already applied the color to the Grid, i recommned you to quit the Style properties of the Grid and see if that helps.
回答4:
I found a different way.
If you click on the grid item in the XAML code, to select it. Then look in the properties window, expand the Brush
property and you will see the "Background
" item. Click on the small black square to the right of the background property, this will bring up a pop up menu. Click the "Convert to Local value
". This will then give you the ability to change the background with the available items underneath. I got mine to be a gradient fill from green to yellow! Ghastly! :-)
来源:https://stackoverflow.com/questions/13920397/changing-the-background-color-of-a-metro-style-app-has-no-effect