views:

101

answers:

3

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.

A: 

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

dkackman
It needs to be editable.
chaiguy
+1  A: 

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 TextBos is that EVERY WPF CONTROL can be TRANSFORMED (zoom, 3d transforms) and ANIMATED by generic standard meassures - so a special approach is simply unneeded.

TomTom
I thought of this, but wouldn't zooming the textbox by a transform simply make the whole thing uniformly bigger? I want the text to still wrap properly, etc.
chaiguy
+1  A: 

This should get you started:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
  <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
Robert Rossney
Hey it works! I'm actually surprised because I can't understand the underlying logic of how adding a transform affects *wrapping* of the text.
chaiguy
Actually I'm now having some troubles, see updated post.
chaiguy