Tutorial :In WPF/XAML how do I change the size of a paragraph of text using a scroll bar?


I'm new to WPF/XAML & I'm just doing a training exercise at the moment.

I've got a noddy application and I want to change the size of the text in a tag based on the position of a scroll bar.

The text is defined by this code:

<FlowDocumentScrollViewer Grid.Row="1">      <FlowDocument>          <Paragraph>              Text goes here          </Paragraph>      </FlowDocument>  </FlowDocumentScrollViewer>  

I'm trying to define a Setter and I've got as far as this:

<Style TargetType="{x:Type Paragraph}">      <Setter Property="FontSize" Value="???" />  </Style>  

But I can't find out what needs to go in place "???". I've tried Googling for the answer to this, but I think I must be using the wrong search terms because I haven't found the answer yet.

I'm guessing that it's going to be really obvious, but I've got to admit I'm stumped.


You can just set the font size with a binding expression like this:

<Paragraph FontSize="{Binding ElementName=scroll1, Path=Value}" />  <ScrollBar x:Name="scroll1"></ScrollBar>  

What you want to look into is the binding expression syntax, because currently intellisense isn't supported there.


The code that I implemented is this:

<Style TargetType="{x:Type Paragraph}">      <Setter Property="FontSize" Value="{Binding ElementName=FontSizeScroll, Path=Value}" />  </Style>  

Which works a treat.


The value of FontSize is just a number that describes the size (in points I think):

<Style TargetType="{x:Type Paragraph}">       <Setter Property="FontSize" Value="12"/>  </Style>  

I don't know if this is the answer you want cos it feels really obvious.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »