0

I have a Binding expression object:

//e come from Validation.Error event
BindingExpression _bindingExpression = e.Error.BindingInError as BindingExpression;

I want to get the Dependecy Property.

For example, if the bindingExpression is a text of TextBox I want to get TextBox.TextProperty, etc..

Is this possible?

Joe Korolewicz
  • 474
  • 4
  • 21
Hodaya Shalom
  • 4,327
  • 12
  • 57
  • 111

1 Answers1

1

Yes from looking at the Documentation you can find a property on the BindingExpression object called TargetProperty which returns a DependencyProperty ( like TextBox.TextProperty).

Ibrahim Najjar
  • 19,178
  • 4
  • 69
  • 95
  • You can give a specific line of code? because I can not find this object in Binding Expression. – Hodaya Shalom Jul 03 '13 at 10:44
  • 1
    @HodayaShalom, `var thePropertyYouWant = _bindingExpression.TargetProperty`, notice that `thePropertyYouWant` is a DependencyProperty and it is the one you are using in the binding like the TextProperty of a TextBox. – Ibrahim Najjar Jul 03 '13 at 10:46
  • I get error : 'System.Windows.Data.BindingExpression' does not contain a definition for 'TargetProperty' and no extension method 'TargetProperty' accepting a first argument of type 'System.Windows.Data.BindingExpression' could be found (are you missing a using directive or an assembly reference?) – Hodaya Shalom Jul 03 '13 at 10:50
  • The TargetProperty Supported in: 4.5, I use 4. – Hodaya Shalom Jul 03 '13 at 10:57
  • @HodayaShalom, since you are using .NET 4 then i will have to ask for more information, what do you want the Dependency Property for, what is your final goal, what are you trying to achieve ? – Ibrahim Najjar Jul 03 '13 at 13:30
  • @HodayaShalom, you can use Reflection i guess but it is a bit hard and painful. – Ibrahim Najjar Jul 03 '13 at 14:29