views:

378

answers:

3

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.

+1  A: 

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.

Rich
ChrisF
A: 

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.

gcores
To the person who upvoted this - I'm afraid it doesn't answer the question. Yes it tells me how to set the font size, but not how to link that to the change in position of the scroll bar.
ChrisF
+1  A: 

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.

ChrisF