为什么ClearType在透明窗口中部分失效?

3
我有一个透明的Window,它运行良好,但是TextBox忽略了ClearTypeRenderOptions.ClearTypeHint="Enabled"已经设置,但是没有任何效果。除了AllowsTransparency="True"AllowsTransparency="True"之外,没有其他的Effect、OpacityMask、VisualBrush、DrawingBrush、Clip或Opacity。

AllowsTransparency="True"

enter image description here

普通窗口上的AllowsTransparency="False"

enter image description here

Xaml示例

<Window x:Class="WpfApplication3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="200"
        Width="300"
        Title="MainWindow"
        AllowsTransparency="True"
        WindowStyle="None">

  <Window.Template>
    <ControlTemplate>

      <Grid Background="White"
            Height="200"
            Width="300"
            RenderOptions.ClearTypeHint="Enabled"
            TextOptions.TextRenderingMode="ClearType"
            TextOptions.TextFormattingMode="Display">

        <StackPanel VerticalAlignment="Center"
                    HorizontalAlignment="Center">
          <Label>Lorem Ipsum Test</Label>
          <TextBlock>Lorem Ipsum Test</TextBlock>
          <TextBox Text="Lorem Ipsum"
                   Background="White" />
        </StackPanel>
      </Grid>

    </ControlTemplate>
  </Window.Template>

</Window>

有什么建议吗?这是一个无法解决的已知问题吗?

更新

使用 Snoop 工具,我发现了一个 TextBoxLineDrawingVisual ,也许它引起了问题?

enter image description here


1
ClearType文本在不完全不透明的背景上显示不正确。中间呈现目标(如Effect、OpacityMask、VisualBrush、DrawingBrush、Clip和Opacity)可能会引入不完全不透明的背景。当WPF检测到绘制文本的缓冲区可能具有透明背景时,它会禁用ClearType。来自这里 - Sinatr
@Sinatr 我知道这一点,但是 TextBox 有一个普通的 Background。顺便问一下,为什么 TextBlock 能工作? - punker76
1个回答

0
这是因为网格的文本附加属性,例如“RenderingMode”,在内部实现时应用于“textblock”而不是“textbox”子元素。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接