[英]UWP set background from dark/light dictionary
var solcolor = (SolidColorBrush)Application.Current.Resources["PopUpsBackground"];
this.Background = new SolidColorBrush(solcolor.Color);
I set the Background of ContentDialogs programmatically but it gets the requested theme color from an application, but I need to get the color that I set.我以编程方式设置了 ContentDialogs 的背景,但它从应用程序中获取了请求的主题颜色,但我需要获取我设置的颜色。 I find this:
我发现这个:
dialog.RequestedTheme = (Window.Current.Content as FrameworkElement).RequestedTheme;
But now I need to get color from the dictionary I need( dark or light) I also find this:但现在我需要从我需要的字典中获取颜色(深色或浅色)我也发现了这个:
Background="{Binding Source={ThemeResource PopUpsBackground}}"
but it does not work either但它也不起作用
UWP set background from dark/light dictionary
UWP 从暗/亮字典设置背景
You need set ThemeDictionaries
in the Application.Resources
like following.您需要在
Application.Resources
中设置ThemeDictionaries
,如下所示。 And custom ContentDialog's style edit the default Background property as your custom value.并且自定义 ContentDialog 的样式将默认的 Background 属性编辑为您的自定义值。 For more detail please refer to this document .
有关详细信息,请参阅此文档。
<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>
Please note, for making ContentDialog new style effect, you need restart your app after change current theme.请注意,要制作 ContentDialog 新样式效果,您需要在更改当前主题后重新启动您的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.