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 回答