Detecting validation errors in Silverlight 4

Posted by jkohlhepp on Stack Overflow See other posts from Stack Overflow or by jkohlhepp
Published on 2010-05-15T21:58:13Z Indexed on 2010/05/15 22:02 UTC
Read the original article Hit count: 739

Filed under:
|
|

I'm using the new Silverlight 4 support for IDataErrorInfo. So I have a POCO object that has implemented the interface, and when a validation rule fires the Silverlight UI correctly shows the error. So that is all working fine.

The POCO object looks like this:

public class SomeDomainClass : IDataErrorInfo
{
    public string SomeString { get; set; }

    public string Error
    {
        get { return String.Empty; }
    }

    public string this[string columnName]
    {
        get
        {
            if (columnName == "SomeString" && PolicyNumber.Contains("%"))
                return "SomeString cannot contain '%'.  You'll ruin everything!!!";
            return String.Empty;
        }
    }
}

However, I want to be able to detect whether or not there are any errors on the page. For example if I have a Save button and I want to disable it if there are errors, or display a message or something.

What is the best way to detect if there are existing validation errors on the page? Is there a facility for this based around the IDataErrorInfo support in Silverlight? Or do I have to track it in the domain model myself?

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about silverlight-4.0