简体   繁体   English

UWP 从暗/亮字典设置背景

[英]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.

相关问题 UWP - 以编程方式将前景色设置为动态明暗主题色 - UWP - Set foreground color to dynamic light and dark theme color programmatically #UWP获取系统主题(浅色/深色) - #UWP get system theme (Light/Dark) 更改UWP中的默认深色背景 - Change default dark background in UWP 当 Windows 10 从深色主题更改为浅色时,如何更改 uwp 应用程序标题栏颜色,反之亦然? - How to change uwp app title bar color when Windows 10 change from dark theme to light and vice versa? 如何在 Xamarin Forms UWP 上设置深色主题? - How to set dark theme on Xamarin Forms UWP? Fluent AcrylicBrush不能在亮,暗,主题等之间切换。UWP - Fluent AcrylicBrush does not switch between Light, Dark, theme etc. UWP UWP RichEditBox 在深色模式下保存并在浅色模式下打开时出现文本颜色问题 - UWP RichEditBox text color issue when saved in dark mode and opened in light mode UWP 将鼠标悬停在位图图标上时,位图图标在暗模式和亮模式之间切换 - UWP Bitmap-Icon is changing between Dark and Light Mode when hovering over it 如果 Windows 10 使用深色主题 (UWP),则设置 TextBlock 文本 - Set TextBlock Text if Windows 10 uses dark theme (UWP) 除了几个基本主题:默认,浅色,深色和高对比度,我是否可以启用无限数量的自定义主题? (UWP) - Can I enable a unlimited amount of custom themes, besides just the few basic themes: Default, Light, Dark, and HighContrast? (UWP)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM