为 ContentDialog 配置叠加背景颜色 [英] Configuring overlay background colour for ContentDialog

查看:27
本文介绍了为 ContentDialog 配置叠加背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用深色主题为通用 Windows 平台编写应用程序,但我注意到,虽然我在使用 ContentDialog 分类叠加层会使整个页面变亮而不是变暗.

I'm writing an app for the universal windows platform using the dark theme and I've noticed that although I've correctly set the requested theme to dark when I display a modal dialog using the ContentDialog class the overlay lightens the overall page rather than darkening it.

对话框显示前:

显示对话框:

由于 ContentDialog 上没有用于控制叠加层的属性,我该如何覆盖正在使用的颜色?

Since there isn't a property on ContentDialog to control the overlay how do I override the colour being used?

推荐答案

经过一些实验,我发现用于控制 ContentDialog 上面显示的叠加层颜色的画笔是SystemControlPageBackgroundBaseMediumBrush 而不是看起来更有可能的 ContentDialogDimmingThemeBrush.

After some experimentation I've found that the brush being used to control the colour of the overlay that a ContentDialog is displayed above is SystemControlPageBackgroundBaseMediumBrushrather than the more likely looking ContentDialogDimmingThemeBrush.

通过检查默认主题定义,可以发现浅色和深色主题都将此画笔设置为颜色资源 SystemBaseMediumColor,浅色主题为 #99000000,而深色主题是 #99FFFFFF.这会导致叠加使浅色主题变暗,并使深色主题变亮.

By inspecting the default theme definitions it emerges that both light and dark themes set this brush to the colour resource SystemBaseMediumColor which on the light theme is #99000000 and on the dark theme is #99FFFFFF. This results in the overlay darkening the light theme and lightening the dark theme.

由于 SystemBaseMediumColor 被其他画笔定义引用,例如用于非活动枢轴标题的画笔定义,因此有必要覆盖 SystemControlPageBackgroundBaseMediumBrush 而不是它仅为深色主题引用的颜色.

Since SystemBaseMediumColor is references by other brush definitions such as those used for inactive pivot titles it's necessary to override SystemControlPageBackgroundBaseMediumBrush rather than the colour it references solely for the dark theme.

为此,我们需要在 App.xaml 或合并到 App.xaml 的资源 XAML 文件中的资源主题字典中重新定义画笔:

To do this we need to redefine the brush in a resource theme dictionary in App.xaml or in a resource XAML file merged into App.xamlalong the lines of:

<Application>

    <Application.Resources>

        <ResourceDictionary>

            <ResourceDictionary.ThemeDictionaries>

                <ResourceDictionary x:Key="Dark">

                    <SolidColorBrush 
                        x:Key="SystemControlPageBackgroundBaseMediumBrush" 
                        Color="#99000000"
                        />

                </ResourceDictionary>

           </ResourceDictionary.ThemeDictionaries>

       </ResourceDictionary>

    </Application.Resources>

</Application>

这篇关于为 ContentDialog 配置叠加背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆