我在UWP template10项目中有很多按钮,当我切换到浅色或深色主题时,我希望自动更改按钮背景颜色。
我进入了我的custom.xaml,并添加了最后5行:
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="CustomColorBrush" Color="{ThemeResource CustomColor}" />
<SolidColorBrush x:Key="ContrastColorBrush" Color="{ThemeResource ContrastColor}" />
<SolidColorBrush x:Key="ExtendedSplashBackground" Color="{ThemeResource CustomColor}" />
<SolidColorBrush x:Key="ExtendedSplashForeground" Color="{ThemeResource ContrastColor}" />
<Style TargetType="controls:PageHeader">
<Setter Property="Background" Value="{ThemeResource CustomColorBrush}" />
<Setter Property="Foreground" Value="{ThemeResource ContrastColorBrush}" />
</Style>
<!-- Change button background-->
<Style TargetType="Button">
<Setter Property="Background" Value="{ThemeResource CustomColorBrush}" />
<Setter Property="Foreground" Value="{ThemeResource ContrastColorBrush}" />
</Style>
</ResourceDictionary>
....
然而,这不起作用。是否有人能够建议如何/在何处进行此操作?
答案 0 :(得分:1)
首次运行应用时,如果您的Styles和SolidColorBrushs可用于您的控制?如果没有,请尝试删除App.xaml中的<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="CustomColor" Color="Orange" />
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="CustomColor" Color="Blue" />
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<SolidColorBrush x:Key="CustomColor" Color="Green" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</Application.Resources>
。
此外,如果您使用&#34;默认&#34;创建ResourceDictionary;作为关键,当主题发生变化时,它不会改变颜色。您应该可以为&#34; Light&#34;指定主题词典。和&#34;黑暗&#34;除了你的&#34; HighContrast&#34;字典。
例如:
在App.xaml中:
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="CustomColorBrush" Color="{ThemeResource CustomColor}" />
<SolidColorBrush x:Key="ContrastColorBrush" Color="{ThemeResource ContrastColor}" />
<SolidColorBrush x:Key="ExtendedSplashBackground" Color="{ThemeResource CustomColor}" />
<SolidColorBrush x:Key="ExtendedSplashForeground" Color="{ThemeResource ContrastColor}" />
<Style TargetType="controls:PageHeader">
<Setter Property="Background" Value="{ThemeResource CustomColorBrush}" />
<Setter Property="Foreground" Value="{ThemeResource ContrastColorBrush}" />
</Style>
<Style TargetType="Button">
<Setter Property="Background" Value="{ThemeResource CustomColorBrush}" />
<Setter Property="Foreground" Value="{ThemeResource ContrastColorBrush}" />
</Style>
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="CustomColorBrush" Color="{ThemeResource CustomColor}" />
<SolidColorBrush x:Key="ContrastColorBrush" Color="{ThemeResource ContrastColor}" />
<SolidColorBrush x:Key="ExtendedSplashBackground" Color="{ThemeResource CustomColor}" />
<SolidColorBrush x:Key="ExtendedSplashForeground" Color="{ThemeResource ContrastColor}" />
<Style TargetType="controls:PageHeader">
<Setter Property="Background" Value="{ThemeResource CustomColorBrush}" />
<Setter Property="Foreground" Value="{ThemeResource ContrastColorBrush}" />
</Style>
<Style TargetType="Button">
<Setter Property="Background" Value="{ThemeResource CustomColorBrush}" />
<Setter Property="Foreground" Value="{ThemeResource ContrastColorBrush}" />
</Style>
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<SolidColorBrush x:Key="CustomColorBrush" Color="{ThemeResource CustomColor}" />
<SolidColorBrush x:Key="ContrastColorBrush" Color="{ThemeResource ContrastColor}" />
<SolidColorBrush x:Key="ExtendedSplashBackground" Color="{ThemeResource CustomColor}" />
<SolidColorBrush x:Key="ExtendedSplashForeground" Color="{ThemeResource ContrastColor}" />
<Style TargetType="controls:PageHeader">
<Setter Property="Background" Value="{ThemeResource CustomColorBrush}" />
<Setter Property="Foreground" Value="{ThemeResource ContrastColorBrush}" />
</Style>
<Style TargetType="Button">
<Setter Property="Background" Value="{ThemeResource CustomColorBrush}" />
<Setter Property="Foreground" Value="{ThemeResource ContrastColorBrush}" />
</Style>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</Page.Resources>
此外,你应该为&#34; Light&#34;,&#34; Dark&#34;添加指定的主题词典。和&#34; HighContrast&#34;在custom.xaml的字典中。
在custom.xaml中:
angular.module('mymodule', []).filter('dateRange', fn)