How to resolve bound object from bindingexpression with WPF?

前端 未结 5 1233
再見小時候
再見小時候 2020-12-14 17:17

Hi does anyone know if there are any inbuilt classes for resolving a bound object from a bindingexpression and it\'s DataItem and property path?

I\'m attempting to w

5条回答
  •  孤城傲影
    2020-12-14 18:10

    Just for further information, PropertyPath resolution is handled by an internal MS class called PropertyPathWorker, which lives in PresentationFramework under MS.Internal.Data. If you open it up in Reflector, you can see it's quite complicated, so I wouldn't recommend trying to duplicate its functionality. It's tightly coupled with the overall Binding architecture.

    The most robust way to support all property path syntax--including attached dependency properties and hierarchical traversal--is probably to create a dummy DependencyObject with a DependencyProperty. You can then create a Binding from your 'owner' path to the dummy dependency property, create a new BindingExpression and then call the expression's UpdateTarget. It's a rather heavy way of accomplishing what, on the surface, looks like a simple task, but I think there are a lot of hidden gotchas in the way property paths are resolved for binding.

提交回复
热议问题