是否可以在样式中使用转换器? [英] Is it possible to use a converter within a style?
本文介绍了是否可以在样式中使用转换器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在样式中使用转换器?例如,我试图创建一个样式化的 TextBlock
,其文本根据 TextBlock
的 ActualHeight
属性调整大小.调整大小将通过转换器完成.
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屋!
查看全文