Home > DeveloperSection > Forums > How to bind to property of object returned by converter
jacob rasel
jacob rasel

Total Post:88

Posted on    July-18-2013 3:12 AM


 1 Reply(s)
 974  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

shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Posted on    July-18-2013 11:19 PM

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}"

Don't want to miss updates? Please click the below button!

Follow MindStick