为 ContentDialog 配置覆盖背景颜色 [英] Configuring overlay background colour for 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 SystemControlPageBackgroundBaseMediumBrush
rather 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.xaml
along 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屋!