Data Binding 101 Expression Syntax: Listing 1

IDataError Implementation.

public class Person:INotifyPropertyChanged, IDataErrorInfo
{
    public string Error
    {
        get
        {
            var attributes = new[] { "Title", "Name" };
            foreach (var attribute in attributes)
            {
                var error = this[attribute];
                if (!string.IsNullOrWhiteSpace(error)) return error;
            }
            return string.Empty;
        }
    }

    public string this[string columnName]
    {
        get
        {
            switch (columnName)
            {
                case "Title":
                    return string.Empty;
                case "Name":
                    return !string.IsNullOrWhiteSpace(Name) ? string.Empty : "Need to specify name";
                default:
                    return string.Empty;
            }

        }
    }
    ...
}

About the Author

Nick Randolph runs Built to Roam, a consulting company that specializes in training, mentoring and assisting other companies build mobile applications. With a heritage in rich client applications for both the desktop and a variety of mobile platforms, Nick currently presents, writes and educates on the Windows Phone platform.

comments powered by Disqus

Featured

Subscribe on YouTube