如何在 UWP 中为 HighContrast 主题设置 TextBlock 背景色
How to set TextBlock background color for HighContrast Theme in UWP
在 Microsoft UWP 应用程序中,我尝试使用 XAML 中的 Grid 设置 TextBlock 背景颜色。默认主题没问题。但是当我启用 HighContrast Theme 时,只有 Filled Text 部分是黑色;而 TextBlock 的剩余部分根据 HighContrast 主题进行更改。我也尝试过使用 Border,但问题仍然存在。我也尝试过 Style 属性,同样的问题。
谁能帮我解决这个问题?
<Grid Height="50" Width="500" Background="{ThemeResource SystemColorHighlightColor}">
<TextBlock Text="High Contrast" Width="250" FontSize="20" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
Comparison with system behavior
How to set c color for HighContrast Theme in UWP
以上行为是设计使然,TextBlock
后台由系统控制。如果要编辑它,请到设置页面找到高对比度设置 -> 背景。编辑 Background
将更改 HighContrast
模型中的 TextBlock
背景。
如果您想让网格具有相同的颜色,请保持 Selected Text
颜色与背景颜色相同。
更新
一般情况下,我们经常将Grid背景设置为ApplicationPageBackgroundThemeBrush
,这样可以使文本块背景与Grid保持一致,避免出现黑块。
<Grid
Width="500"
Height="50"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
>
<TextBlock
Width="250"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20"
SelectionChanged="TextBlock_SelectionChanged"
Text="High Contrast"
/>
</Grid>
更新 1
请检查 TextBlock HighContrastAdjustmen
属性。如果我们将其设置为 None ,黑色块将消失。
<Grid
Width="500"
Height="50"
Background="{ThemeResource SystemColorHighlightColor}"
>
<TextBlock
Width="250"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20"
Foreground="Black"
HighContrastAdjustment="None"
Text="High Contrast"
Visibility="Visible"
/>
</Grid>
在 Microsoft UWP 应用程序中,我尝试使用 XAML 中的 Grid 设置 TextBlock 背景颜色。默认主题没问题。但是当我启用 HighContrast Theme 时,只有 Filled Text 部分是黑色;而 TextBlock 的剩余部分根据 HighContrast 主题进行更改。我也尝试过使用 Border,但问题仍然存在。我也尝试过 Style 属性,同样的问题。
谁能帮我解决这个问题?
<Grid Height="50" Width="500" Background="{ThemeResource SystemColorHighlightColor}">
<TextBlock Text="High Contrast" Width="250" FontSize="20" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
Comparison with system behavior
How to set c color for HighContrast Theme in UWP
以上行为是设计使然,TextBlock
后台由系统控制。如果要编辑它,请到设置页面找到高对比度设置 -> 背景。编辑 Background
将更改 HighContrast
模型中的 TextBlock
背景。
如果您想让网格具有相同的颜色,请保持 Selected Text
颜色与背景颜色相同。
更新
一般情况下,我们经常将Grid背景设置为ApplicationPageBackgroundThemeBrush
,这样可以使文本块背景与Grid保持一致,避免出现黑块。
<Grid
Width="500"
Height="50"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
>
<TextBlock
Width="250"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20"
SelectionChanged="TextBlock_SelectionChanged"
Text="High Contrast"
/>
</Grid>
更新 1
请检查 TextBlock HighContrastAdjustmen
属性。如果我们将其设置为 None ,黑色块将消失。
<Grid
Width="500"
Height="50"
Background="{ThemeResource SystemColorHighlightColor}"
>
<TextBlock
Width="250"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20"
Foreground="Black"
HighContrastAdjustment="None"
Text="High Contrast"
Visibility="Visible"
/>
</Grid>