views:

104

answers:

2

*Is it possible to get validation errors(produced by the binding source through IDataErrorInfo or INotifyDataErrorInfo) *without accessing data source?

The point is to get the error message which is going to be displayed.

Thank you in advance.

EDIT: "without accessing data source" means that I don't want to get the error messages through the properties implementing IDataErrorInfo interface on the data source.

+2  A: 

Not sure what you mean by "without accessing the data source", but you can access the errors also via the binding with

{Binding RelativeSource={RelativeSource Self},Path=(Validation.Errors)[0].ErrorContent}

Be aware that in case there are no errors, this will throw an exception. So depending on what you want to do, check if there are errors with the "Validation.HasErrors" Property.

Also check this example on how to do it properly:

AKrebs
OK that helps. I actually need to get the errors form code behind but your answer gives me some useful directions so thanks.
Koynov
+1  A: 

Hello

"without accessing data source" means that you can see validation errors created in set{...} part of property owned by business class. E.g. we have Person class:

public class Person
{
string firstName;
public string FirstName
{
get{return firstName;}
set
{
if (String.IsNullOrEmpty(value))
throw new Exception("First name should be provided!");
firstName = value;
}
}
}

Something like that

MagicMax