WPF Databinding and cascading Converters?

穿精又带淫゛_ 提交于 2019-12-03 11:45:37

You could try to use a MultiBinding, and bind twice to the same source, but with different converts on the single bindings. Something like:

<SomeControl>
    <SomeControl.Visibility>
        <MultiBinding Converter="{StaticResource combiningConverter}">
            <Binding Path="SomeProperty" Converter="{StaticResource firstConverter}"/>
            <Binding Path="SomeProperty" Converter="{StaticResource secondConverter}"/>
        </MultiBinding>
    </SomeControl.Visibility>
</SomeControl>

Then in 'combiningConverter' you put the logic to combine the values coming from the two bindings.

You may be looking for a solution similar to Josh Smith's "Piping Value Converters".

In his article, he presents the following:

<local:ValueConverterGroup x:Key="statusDisplayNameGroup">
  <local:IntegerStringToProcessingStateConverter  />
  <local:EnumToDisplayNameConverter />
</local:ValueConverterGroup> 

And then uses the multi-value converters as follows:

<TextBlock Text="{Binding XPath=@Status, 
             Converter={StaticResource statusDisplayNameGroup}}" />

Hope this helps!

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