How to resolve bound object from bindingexpression with WPF?

前端 未结 5 1215
再見小時候
再見小時候 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 17:49

    For people in the future who stumble on this question:

    When .NET 4.5 becomes available it will have a number of new properties on the BindingExpression to greatly simplify what you are looking for.

    ResolvedSource - The object that is actually being bound to, helpful when you have a binding source like 'grandparent.parent.me.Name'. This would return the 'me' object.

    ResolvedSourcePropertyName - The name of the property on the ResolvedSource that is bound to. In the case above, "Name".

    Similarly, there will be Target, and TargetName properties.

    With these helper properties on BindingExpression you could use some shorter and much more simplified reflection that is more likely to work in extreme situations (indexers).

提交回复
热议问题