Sheen
Sheen

Reputation: 3441

Why UWP ApplicationPageBackgroundThemeBrush is always white?

I am beginner. I have below simplest code:

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

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    </Grid>
</Page>

I test it in Windows mobile 10 emulator. No matter how I change OS theme, dark or light, my app's background is always white. So what is correct way to set theme-dependent app-wide colours?

Upvotes: 8

Views: 5876

Answers (2)

Sheen
Sheen

Reputation: 3441

I eventually find out the problem by googling about. The problem is caused by the VS2015 project template. In app.xaml, there is a line to set RequestedTheme="Light". I removed the line and things are fine now. Wasted me 2 hours. Hope you see my answer and therefore save time.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/c12cdba4-093f-474a-9d21-6e447aaa2adf/uwp-applicationpagebackgroundthemebrush-is-always-white?forum=wpdevelop

Upvotes: 15

Pedro G. Dias
Pedro G. Dias

Reputation: 3222

Set the background on the <Grid> element, like so:

<Grid Background="Blue"></Grid>

For your foreground text, you can set a default style in App.Xaml like so:

<App.Resources>
  <Style TargetType="TextBox">
    <Setter Property="Foreground" Value="Red" />
  </Style>
</App Resources>

As long as you're setting styles on element names and not on named things, the style will apply to all elements of that type. You can also inherit styles to repeat commonly used styles.

Upvotes: 0

Related Questions