HOW TO BIND TO PROPERTY OF OBJECT RETURNED BY CONVERTER

jacob rasel

Total Post:88

Points:616
Posted by  jacob rasel
WPF 
WPF
 1021  View(s)
Ratings:
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:

// NOTE: FOLLOWING IS NOT SUPPORTED BY WPF

// 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. shreesh chandra shukla

    Post:105

    Points:735
    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}"

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!