In WPF/XAML how do I change the size of a paragrap

2019-08-27 22:24发布

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.

3条回答
\"骚年 ilove
2楼-- · 2019-08-27 22:32

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.

查看更多
forever°为你锁心
3楼-- · 2019-08-27 22:53

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.

查看更多
Animai°情兽
4楼-- · 2019-08-27 22:59

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.

查看更多
登录 后发表回答