如何获取绑定到WPF控件的属性和对象

时间:2013-07-29 10:09:39

标签: wpf xaml binding property-binding

我想解决对象实例和控件绑定的属性,无论绑定是如何定义的。

我做了以下事情:

BindingExpression bindingExpression = 
baseEdit.GetBindingExpression(BaseEdit.EditValueProperty);

if (bindingExpression == null) continue;

Binding binding = bindingExpression.ParentBinding;

string propertyName = binding.Path.Path;

以上情况适用于大多数场景,但有时候它并没有给我我想要的东西 - 我明白为什么它没有,但我找不到找到我想要的方法。

例如,以下内容打破了我所拥有的内容,因为它返回DataContext.CurrentMileage,这不是我想要的。我只想要CurrentMileage

{Binding DataContext.CurrentMileage, ValidatesOnDataErrors=True, RelativeSource={RelativeSource AncestorType={x:Type view:ViewBase}}}

0 个答案:

没有答案
相关问题