开发者

TextBox data binding validation

*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 i开发者_Python百科s 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.


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:


"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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜