是否可以“缩放” WPF RichTextBox 中的文本?
我注意到 WinForms RichTextBox 有一个 ZoomFactor
属性,我认为这正是我想要的 - 不幸的是,在 WPF 变体中似乎完全缺少该属性。
有什么方法可以实现相同的功能(增加/减少整个文档的可见文本大小而不实际更改底层 RTF)?
更新: 虽然在 RichTextBox 上设置 LayoutTransform 似乎可以在非常简单的设置下工作,但它与设置 ZoomFactor 并不完全相同,因为以下几点:
- 首先,滚动条也会缩放。这看起来很愚蠢。
- 其次,在我的应用程序中(出于某种原因,但不是在 Kaxaml 中——我将探索这一点以找出原因),文本是位图缩放的,因此它只是放大渲染的文本,而不是放大矢量缩放它,使其平滑。这是我正在谈论的示例(注意大的自定义滚动条):
更新 2: 好的,我发现位图缩放是由于将 TextOptions.TextFormattingMode 设置为 Display
而不是 Ideal
引起的。将其设置为理想状态会重新引入矢量缩放。
然而仍然有那个讨厌的滚动条!我的意思是,一种选择是禁用 RichTextBox 上的滚动并将其包装在 ScrollViewer 中,但我想知道这是否会降低性能。我还想知道如果我这样做的话文本换行是否仍然有效。
I noticed the WinForms RichTextBox has a ZoomFactor
property that I assume is exactly what I want--unfortunately this seems to be entirely missing on the WPF variant.
Is there any way I can achieve the same functionality (increasing/decreasing the visible text size of the whole document without actually changing the underlying RTF)?
Update: While setting a LayoutTransform on the RichTextBox does seem to work under very simple settings, it's not exactly the same as setting ZoomFactor because of a couple things:
- First, the scroll bar is zoomed also. This just looks silly.
- Second, in my app (for some reason, but not in Kaxaml--I'll explore this to figure out why), the text is bitmap zoomed so that it just enlarges the rendered text as opposed to vector-zooming it so it's smooth. Here's an example of what I'm talking about (note the way-big custom scroll bar):
Update 2: Okay I discovered that the bitmap zooming was being caused by setting TextOptions.TextFormattingMode to Display
instead of Ideal
. Setting it to ideal reintroduces vector zooming.
However there is still that pesky scroll bar! I mean one option is to disable scrolling on the RichTextBox and wrap it in a ScrollViewer, but I wonder if that would deteriorate performance. I also wonder if text wrapping would still work if I did that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这应该可以帮助您开始:
This should get you started:
您需要返回并阅读 WPF 的基础知识。逐项。在“变形”站停下来。 TextBox 中缺少 ZoomFactor 的原因是每个 WPF 控件都可以通过通用标准措施进行转换(缩放、3D 转换)和动画 - 因此根本不需要特殊方法。
You need to get back and read the basics of WPF. Item by Item. Stop at TRANSFORMS. The reason that a ZoomFactor is missing in the TextBox is that EVERY WPF CONTROL can be TRANSFORMED (zoom, 3d transforms) and ANIMATED by generic standard measures - so a special approach is simply unneeded.
看看我的 FlowDocumentReader认为这有您正在寻找的东西。
Take a look at the FlowDocumentReader as I think that has what you are looking for.