Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is it possible to use a converter within a style? For instance I am trying to create a styled TextBlock whose text resizes based on the ActualHeight property of the TextBlock. The resizing would be done via a converter.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
238 views
Welcome To Ask or Share your Answers For Others

1 Answer

Yes, this is possible. For example:

<Style TargetType="TextBlock">
    <Setter Property="FontSize">
        <Setter.Value>
            <Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}">
                <Binding.Converter>
                    <MyConverter/>
                </Binding.Converter>
            </Binding>
        </Setter.Value>
    </Setter>
</Style>

Depending on your exact scenario, you might also be able to use the more succinct:

<Style TargetType="TextBlock">
    <Setter Property="FontSize" Value="{Binding ActualHeight, RelativeSource={RelativeSource Self}, Converter={StaticResource MyConverter}}"/>
</Style>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...