是否有可能使用样式中的转换器? [英] Is it possible to use a converter within a style?

查看:165
本文介绍了是否有可能使用样式中的转换器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用样式中的转换器?比如我想创建一个风格的TextBlock 其文本调整大小根据<$ C $的的ActualHeight 属性C>的TextBlock 。调整大小将通过转换器来实现。

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.

推荐答案

是的,这是可能的。例如:

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>

这篇关于是否有可能使用样式中的转换器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆