0

イベントを発生させたバインディングを取得することは可能Validation.Errorですか?

例: テキスト ボックスでこのイベントにサインアップしました。

 <TextBox Validation.Error="My_Error" Text="{Binding MyProp,UpdateSourceTrigger=PropertyChanged,NotifyOnValidationError=True}" />

このイベントは、検証エラーが発生したときに実行され、次の関数に到達します。

private void My_Error(object sender, ValidationErrorEventArgs e)
{
  //Here I want to get the property for which fired the event (MyProp). Is it possible?
}
4

1 に答える 1

3

私はそれを行う方法を見つけました:

        viewmodel Vm = (e.Error.BindingInError as BindingExpression).DataItem as viewmodel ;// Take viem model from data item. (I think that data item is the binding of the window - not sure)

        string propName= (e.Error.BindingInError as BindingExpression).ParentBinding.Path.Path;// The path is the prop name

        System.Reflection.PropertyInfo prop = Vm.GetType().GetProperty(propName);// Here the prop

        var valProp = prop.GetValue(Vm, null);//Here the value
于 2013-06-30T09:25:19.987 に答える