Why UWP ApplicationPageBackgroundThemeBrush is always white?

元气小坏坏 提交于 2020-12-05 08:10:43

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/36206027/why-uwp-applicationpagebackgroundthemebrush-is-always-white

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!