Is it possible to use a converter within a style?

送分小仙女□ 提交于 2019-11-27 21:24:10

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>
yannduran

I managed to get something similar to work by using:

<Setter Property="Text">
  <Setter.Value>
    <Binding Path="CompanyName">
      <Binding.Converter>
        <conv:UppercaseConverter/>
      </Binding.Converter>
    </Binding>
  </Setter.Value>
</Setter>

Hope it works for you too.

Yann

PS - CompanyName is the name of the actual ViewModel property I was binding the textblock to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!