views:

1150

answers:

2

hi there,

i wonder if it is possible to cascade converters when using wpf databinding. e.g. something like

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

is it possible at all or do i have to create a custom converter that combines the functionality of converter A and B?

+7  A: 

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!

Brad Leach
+2  A: 

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.

Enrico Campidoglio