
[英]UWP - Set foreground color to dynamic light and dark theme color programmatically
[英]UWP set background from dark/light dictionary
var solcolor = (SolidColorBrush)Application.Current.Resources["PopUpsBackground"];
this.Background = new SolidColorBrush(solcolor.Color);
我以编程方式设置了 ContentDialogs 的背景,但它从应用程序中获取了请求的主题颜色,但我需要获取我设置的颜色。 我发现这个:
dialog.RequestedTheme = (Window.Current.Content as FrameworkElement).RequestedTheme;
但现在我需要从我需要的字典中获取颜色(深色或浅色)我也发现了这个:
Background="{Binding Source={ThemeResource PopUpsBackground}}"
但它也不起作用
UWP 从暗/亮字典设置背景
您需要在Application.Resources
中设置ThemeDictionaries
,如下所示。 并且自定义 ContentDialog 的样式将默认的 Background 属性编辑为您的自定义值。 有关详细信息,请参阅此文档。
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="DialogColor" Color="Red" />
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="DialogColor" Color="SeaGreen" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<Style TargetType="ContentDialog">
<Setter Property="Foreground" Value="{ThemeResource ContentDialogForeground}" />
<Setter Property="Background" Value="{ThemeResource DialogColor}" />
<Setter Property="BorderBrush" Value="{ThemeResource ContentDialogBorderBrush}" />
<Setter Property="IsTabStop" Value="False" />
</Style>
</ResourceDictionary>
请注意,要制作 ContentDialog 新样式效果,您需要在更改当前主题后重新启动您的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.