WPF文字渲染问题 [英] WPF Text rendering problem
问题描述
我创建了一个类似于 TabControl 的自定义控件.它工作得很好,除了当我调整内容大小时标题项中的文本变得模糊.例如,它可以如下所示:
I created a custom control similar to TabControl. It works nice, except that the text in header items gets blury when I resize the content. It can, for example look like this:
不仅是文本,文本周围的框也可以变得不垂直.查看常规"项周围的蓝色边框:
Not only the text, but the box around the text can also get non-vertical. See the blue border around the "General" item:
是什么导致了这个问题?我已经设置了 SnapToDevicePixels = True.感谢您的任何想法!
What is causing this problem? I have set SnapToDevicePixels = True. Thanks for any ideas!
编辑:
我使用的是 .NET 4.0.TextOptions.TextFormattingMode 设置为显示".
I'm using .NET 4.0. TextOptions.TextFormattingMode is set to "Display".
如果我在显示按钮的 ItemsControl 的样式中应用 DropShadowEffect 效果,就会出现模糊文本和背景的整个问题.这是效果的代码:
The whole problem with fuzzy text and background occurs if I apply a DropShadowEffect effect in the style for ItemsControl which displays the buttons. This is the code for the Effect:
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect Direction="0" ShadowDepth="1" BlurRadius="10" Opacity="0.2" Color="Black" />
</Setter.Value>
</Setter>
如果未启用此代码,文本和边框会很好地显示.
If this code is not enabled, the the text and the borders get displayed nicely.
推荐答案
我怀疑您自己说过:SnapToDevicePixels
如果您调整文本大小使其跨像素显示,则会破坏文本渲染.您可能希望在边框/背景上保留 SnapToDevicePixels="True"
,但为文本元素关闭它.
I suspect you've said it yourself: SnapToDevicePixels
will ruin text rendering if you've resized the text so it displays across pixels. You probably want to keep SnapToDevicePixels="True"
on your borders/backgrounds, but turn it off for the text elements.
至于你的边框……你能把xaml贴出来吗?我猜您不只是使用带圆角的单个元素 - 您是否将该选项卡的边缘绘制为三个单独的线?
As for your border... can you post the xaml? I'm guessing that you're not using just a single element with rounded corners - are you drawing the edge of that tab as three separate lines?
这篇关于WPF文字渲染问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!