1

在 Microsoft UWP 应用程序中,我尝试使用 XAML 中的 Grid 设置 TextBlock 背景颜色。默认主题没问题。但是当我启用高对比度主题时,只有填充文本部分是黑色的;而 TextBlock 的剩余部分则根据 HighContrast Theme 进行更改。我也尝试过使用 Border,但问题仍然存在。我也尝试了 Style 属性,同样的问题。

谁能帮我解决这个问题?

<Grid Height="50" Width="500" Background="{ThemeResource SystemColorHighlightColor}">
        <TextBlock Text="High Contrast" Width="250" FontSize="20" VerticalAlignment="Center" HorizontalAlignment="Center"/>
    </Grid>

如果您想要清晰的视野,请检查输出图像

与系统行为比较

4

1 回答 1

0

如何在 UWP 中为 HighContrast 主题设置 c 颜色

上述行为是设计使然,TextBlock后台由系统控制。如果你想编辑它,请到设置页面找到高对比度设置 ->背景。并且编辑Background将改变模型中TextBlock的背景HighContrast

在此处输入图像描述

如果要使网格具有相同的颜色,请保持Selected Text颜色与背景颜色相同。

更新

一般来说,我们经常设置网格背景,ApplicationPageBackgroundThemeBrush这样可以保持文本块背景与网格相同,然后避免显示黑色块。

<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>
于 2020-05-26T09:29:05.630 回答