将FlowDocument放在带有自定义玻璃的窗口中时,子元素中的ClearType丢失 [英] FlowDocument loses ClearType in child elements when placed in window with custom glass

查看:115
本文介绍了将FlowDocument放在带有自定义玻璃的窗口中时,子元素中的ClearType丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,新的WPF 4文本呈现看起来不错,但是要在窗口上启用航空玻璃效果,则需要将背景更改为透明,这当然会禁用ClearType呈现.

So the new WPF 4 text rendering looks great, but enabling the aero glass effect on a window requires that you change the background to transparent, which of course disables ClearType rendering.

使用提供的RenderOptions.ClearTypeHint = Enabled,您可以指定子元素以从树中的该点重新启用ClearType渲染.我发现了其他一些话题,这些话题涉及为RichTextBox和FlowDocumentScrollViewer内部使用的ScrollViewer进行此操作,并且创建自定义样式确实可以解决该问题,以便我的FlowDocument再次获得ClearType呈现.

Using the provided RenderOptions.ClearTypeHint=Enabled allows you to designate child elements to reenable ClearType rendering from that point in the tree. I've found a few other topics that talk about doing this for the ScrollViewer used internally inside RichTextBox and FlowDocumentScrollViewer, and creating a custom style does indeed fix it so that my FlowDocument gets ClearType rendering again.

但是,这仅适用于FlowDocument中的顶级段落.如果添加浮动对象,图形或表格,其中的任何文本将再次变为无法解释的灰度.我知道应该归咎于玻璃效果,因为禁用它会重新启用ClearType渲染.

However, this only applies to top level paragraphs in the FlowDocument. If I add floaters or figures, or a table, any text inside them is inexplicably grayscale again. I know that the glass effect is to blame, since disabling it reenables the ClearType rendering.

我用Snoop浏览了可视树,但是主要内容(正确呈现)和子内容(灰度)都具有相似的元素层次结构,而没有我可以附加RenderOptions.ClearTypeHint的任何内容.

I looked through the visual tree with Snoop, but both the main content (which renders properly) and the sub-content (which is grayscale) have similar element hierarchies without anything to which I can attach RenderOptions.ClearTypeHint.

有人遇到这个问题吗?有解决方法或解决方案吗?我检查了Connect,但是没有关于此的任何bug归档.这是一个很烦人的问题.

Has anyone run into this problem? Is there a workaround or a solution? I checked Connect but there isn't any bug filed about this. It's quite an annoying problem.

推荐答案

经过大量研究,并比较了不同控件在航空玻璃上的工作方式,我找到了一些答案. TextBox控件也无法正常工作,但是FlowDocument的某些部分以及诸如TextBlock之类的控件都可以正常工作,这促使我探索原因.

After doing a lot more research, and comparing the way different controls work on and off of aero glass, I've found a few answers. The TextBox control doesn't work properly either, but portions of FlowDocument and things like TextBlock do, which prompted me to explore why.

在反射器中浏览了一段时间后,我发现当使用高级文本格式API获取文本并将其呈现到绘图上下文时,RenderOption标志实际上被忽略了,因为绘图系统从视觉的根部知道(窗口)启用了透明度.一旦发生这种情况,世界上所有的RenderOptions标志都不会找回ClearType.

After digging around in reflector for a while, I found that when using the advanced text formatting APIs to get text and render it onto a drawing context, the RenderOption flags essentially go ignored, since the drawing system knows from the root visual (the window) that transparency was enabled. Once that happens, all the RenderOptions flags in the world aren't going to get ClearType back.

我确实偶然发现了一种解决方法.如果您有权访问DrawingContext并自己进行低级文本渲染,则可以在文本后面进行填充来绘制DrawRectangle,然后重新启用ClearType.我认为这是渲染器确保具有适当背景可绘制的唯一方法.

I did happen to stumble on a work-around though. If you have access to the DrawingContext and are doing the low-level text rendering yourself, you can do a DrawRectangle behind the text with a fill, and ClearType gets reenabled. I assume that this is the only way for the renderer to be sure that it has a proper background to draw on.

因此,总而言之,您需要绘制自己的文本,并且还需要在文本后使用相同的DrawingContext显式绘制背景,以使ClearType正确呈现.

So in summary, you need to do your own text drawing, and additionally you need to explicitly draw a background using the same DrawingContext behind your text in order for ClearType to get rendered properly.

这篇关于将FlowDocument放在带有自定义玻璃的窗口中时,子元素中的ClearType丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆