|
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
namespace PaulStovell.Samples.WpfValidation
{
public class AdvancedCustomer : IDataErrorInfo, INotifyPropertyChanged
{
private string _name;
private string _address;
public string Name
{
get { return _name; }
set
{
_name = value;
this.OnPropertyChanged(new PropertyChangedEventArgs("Name"));
}
}
public string Address
{
get { return _address; }
set
{
_address = value;
this.OnPropertyChanged(new PropertyChangedEventArgs("Address"));
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, e);
}
}
#endregion
#region IDataErrorInfo Members
public string Error
{
get { return this[null]; }
}
public string this[string propertyName]
{
get
{
string result = string.Empty;
propertyName = propertyName ?? string.Empty;
if (propertyName == string.Empty || propertyName == "Name")
{
if (string.IsNullOrEmpty(this.Name))
{
result += "Name is mandatory." + Environment.NewLine;
}
}
if (propertyName == string.Empty || propertyName == "Address")
{
if (string.IsNullOrEmpty(this.Address) || this.Address.Length > 30)
{
result += "Address is mandatory and must be less than 30 letters."
+ Environment.NewLine;
}
}
return result.TrimEnd();
}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
My name is
Paul Stovell. I live in Brisbane and develop an automated release management product,
Octopus Deploy. Prior to working on Octopus I worked for an investment bank in London, and for
Readify. I also work on
a few open source projects. I am a Microsoft MVP for Client Application Development.