是否可以“缩放” WPF RichTextBox 中的文本?

发布于 2024-09-14 01:08:10 字数 828 浏览 4 评论 0原文

我注意到 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):

alt text

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

韵柒 2024-09-21 01:08:10

这应该可以帮助您开始:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <DockPanel LastChildFill="True">  
     <Slider x:Name="Scale" DockPanel.Dock="Bottom" Minimum="1" Maximum="20"/>
     <RichTextBox>
      <RichTextBox.LayoutTransform>
        <ScaleTransform ScaleX="{Binding ElementName=Scale, Path=Value}" ScaleY="{Binding ElementName=Scale, Path=Value}"/>
      </RichTextBox.LayoutTransform>
     </RichTextBox>
  </DockPanel>
</P

This should get you started:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <DockPanel LastChildFill="True">  
     <Slider x:Name="Scale" DockPanel.Dock="Bottom" Minimum="1" Maximum="20"/>
     <RichTextBox>
      <RichTextBox.LayoutTransform>
        <ScaleTransform ScaleX="{Binding ElementName=Scale, Path=Value}" ScaleY="{Binding ElementName=Scale, Path=Value}"/>
      </RichTextBox.LayoutTransform>
     </RichTextBox>
  </DockPanel>
</P
风筝在阴天搁浅。 2024-09-21 01:08:10

我注意到 WinForms RichTextBox 有
我假设的 ZoomFactor 属性是
正是我想要的——不幸的是
这似乎完全缺失
WPF 变体。

您需要返回并阅读 WPF 的基础知识。逐项。在“变形”站停下来。 TextBox 中缺少 ZoomFactor 的原因是每个 WPF 控件都可以通过通用标准措施进行转换(缩放、3D 转换)和动画 - 因此根本不需要特殊方法。

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.

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.

回眸一遍 2024-09-21 01:08:10

看看我的 FlowDocumentReader认为这有您正在寻找的东西。

Take a look at the FlowDocumentReader as I think that has what you are looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文