我的应用程序以“Light”内置主题运行。
每当我的应用程序运行时切换到另一个高对比度主题,某些颜色会得到不正确的值。
例如,当我的应用程序运行时,当我从无主题切换到HighContrastBlack时,我得到HighContrastWhite中定义的颜色......
当我在Windows设置中切换主题后重新启动应用程序时,没有问题。
只有使用未使用ThemeResource作为颜色的画笔才会发生这种情况。例如FileExplorerBorderBrush。
使用“ThemeResource”代替“StaticResource”对画笔进行引用,所以这也不是问题
的App.xaml:
<Application
x:Class="My_App.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:My_App"
RequestedTheme="Light">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/SplitViewStyles.xaml" />
<ResourceDictionary Source="Styles/PageStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
PageStyles.xaml:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:My_App.Styles">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="PageBackgroundBrush" Color="{ThemeResource PageBackgroundColor}" />
<SolidColorBrush x:Key="BlueAccentColorBrush" Color="{ThemeResource BlueAccentColor}" />
<SolidColorBrush x:Key="OrangeAccentColorBrush" Color="{ThemeResource OrangeAccentColor}" />
<SolidColorBrush x:Key="LabelTextColorBrush" Color="{ThemeResource LabelTextColor}" />
<SolidColorBrush x:Key="AppHeaderColorBrush" Color="{ThemeResource BlueAccentColor}" />
<SolidColorBrush x:Key="FileExplorerBorderBrush" Color="{ThemeResource BlueAccentColor}" />
<SolidColorBrush x:Key="PaneBackgroundBrush" Color="WhiteSmoke" />
<SolidColorBrush x:Key="SettingsPageBackgroundBrush" Color="White" />
<SolidColorBrush x:Key="TopBarDividerLineBrush" Color="#3a3a3a" />
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrastCustom">
<SolidColorBrush x:Key="PageBackgroundBrush" Color="{ThemeResource SystemColorWindowColor}" />
<SolidColorBrush x:Key="BlueAccentColorBrush" Color="Blue" />
<SolidColorBrush x:Key="OrangeAccentColorBrush" Color="Orange" />
<SolidColorBrush x:Key="LabelTextColorBrush" Color="{ThemeResource SystemColorWindowTextColor}" />
<SolidColorBrush x:Key="AppHeaderColorBrush" Color="Blue" />
<SolidColorBrush x:Key="FileExplorerBorderBrush" Color="Blue" />
<SolidColorBrush x:Key="PaneBackgroundBrush" Color="{ThemeResource SystemColorWindowColor}" />
<SolidColorBrush x:Key="SettingsPageBackgroundBrush" Color="{ThemeResource SystemColorWindowColor}" />
<SolidColorBrush x:Key="TopBarDividerLineBrush" Color="Blue" />
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrastBlack">
<SolidColorBrush x:Key="PageBackgroundBrush" Color="{ThemeResource SystemColorWindowColor}" />
<SolidColorBrush x:Key="BlueAccentColorBrush" Color="Blue" />
<SolidColorBrush x:Key="OrangeAccentColorBrush" Color="Orange" />
<SolidColorBrush x:Key="LabelTextColorBrush" Color="{ThemeResource SystemColorWindowTextColor}" />
<SolidColorBrush x:Key="AppHeaderColorBrush" Color="Blue" />
<SolidColorBrush x:Key="FileExplorerBorderBrush" Color="Yellow" />
<SolidColorBrush x:Key="PaneBackgroundBrush" Color="{ThemeResource SystemColorWindowColor}" />
<SolidColorBrush x:Key="SettingsPageBackgroundBrush" Color="{ThemeResource SystemColorWindowColor}" />
<SolidColorBrush x:Key="TopBarDividerLineBrush" Color="Yellow" />
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrastWhite">
<SolidColorBrush x:Key="PageBackgroundBrush" Color="{ThemeResource SystemColorWindowColor}" />
<SolidColorBrush x:Key="BlueAccentColorBrush" Color="Blue" />
<SolidColorBrush x:Key="OrangeAccentColorBrush" Color="Orange" />
<SolidColorBrush x:Key="LabelTextColorBrush" Color="{ThemeResource SystemColorWindowTextColor}" />
<SolidColorBrush x:Key="AppHeaderColorBrush" Color="Blue" />
<SolidColorBrush x:Key="FileExplorerBorderBrush" Color="Blue" />
<SolidColorBrush x:Key="PaneBackgroundBrush" Color="{ThemeResource SystemColorWindowColor}" />
<SolidColorBrush x:Key="SettingsPageBackgroundBrush" Color="{ThemeResource SystemColorWindowColor}" />
<SolidColorBrush x:Key="TopBarDividerLineBrush" Color="Blue" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>