Advertise with us

How to bind to property of object returned by converter

Posted by  jacob rasel
 1501  View(s)
Rate this:
HI mindstick!

I'm trying to bind to a value, run a converter over it, and then display a property of that value. Having the Converter directly return the property I want wouldn't work, as I need property changes to be tracked.

What I'm trying to achieve would be something like this:


// A 'Binding' cannot be set on the 'Source' property of type 'Binding'.

// A 'Binding' can only be set on a DependencyProperty of a DependencyObject.

Text={Binding TextField Source={Binding SomeValue, Converter={StaticResource GetObjectFromValueConverter}}}`

Ideally, this would all be wrapped up in a simple markup extension.

Text={l:GetTextField SomeValue}

Problem is, I haven't been able to find any way to do this other than bind the Tag of the element to the converter, and then bind the target field to the property as follows:

Tag={Binding SomeValue, Converter={StaticResource GetObjectFromValueConverter}}

Text={Binding Tag.TextField, RelativeSource={RelativeSource Self}}

This is obviously cumbersome, limited (you only get one Tag field) and feels abusive. How else can I go about achieving what I want whilst monitoring for changes of TextField though?

thank in advance

  1. Re: How to bind to property of object returned by converter

    Your Answer!

    try this

    You can bind the DataContext of the TextBox, instead of the Tag. That will make your other bindings much simpler:

    DataContext="{Binding SomeValue, Converter={StaticResource GetObjectFromValueConverter}}"

    Text="{Binding TextField}"