none
How to use CLR property as binding target?

    Question

  • Hi all,

    I have created a custom binding class that inherits from MultiBinding. It contains a property 'ObjectInstance' which basically performs the same task as the ObjectInstance property in the ObjectDataProvider. Creating my own binding class was the conclusion of a lot of googling, experimentation and a couple of threads on this forum; I don't think I can achieve what I'm after any other way.

    I have successfully created and used my binding class in XAML, but I had to set the ObjectInstance in code (in this case to the DataContext of the control being bound). I tried to bind the ObjectInstance but I get an error because MultiBinding (from which my class inherits) is not a DependencyObject.

    I've tried a few things like embedding a DependencyObject in my class as a property and binding to it (which the same error as above). Apparently attached properties can only be used by DependencyObjects. When my class is instantiated and used as a binding, it doesn't have a reference to the control being bound or anything else of use, so I can't add code to my class to get an ObjectInstance based on a string (path) etc.

    I bound the ObjectInstance property to a DP in the Window in which it was used by setting the binding to OneWayToSource, but I still had to do it in code to get a reference to the Window which defeats the purpose.

    Does anyone have any ideas?


    <rant>I read somewhere that the decision to not make Bindings inherit from DependencyObject was by design to protect developers from themselves, but after days of frustration and googling for workarounds, I'm not impressed.</rant>

    Thursday, July 24, 2008 5:44 AM

Answers

  • As far as I know, the source of a binding can be any .NET property on any .NET object, but  the target property has to be a dependency property. So, this might be a dead end...

    You could try to get Beatriz Costa's attention. She is the Databinding Queen of WPF. And she is way overdue with updating her blog, so maybe you can wake her up :-)

    These guys also love to solve unsolvable problems so check out their blogs and try to get their attention.

    hth,
    Marcel
    • Marked as answer by Marco Zhou Wednesday, July 30, 2008 11:19 AM
    Thursday, July 24, 2008 7:26 AM