色んな物に影響されまくって、とりあえず ViewModel を作ってみた。

こんな感じで実装したら、

// ViewModel
public class Data : ViewModelBase
{
  private readonly Property _id;
  [RequiredValidator("必須")]
  [Int32RangeValidator("0 以上", MinValue=0)]
  public Property Id
  {
    get { return this._id; }
  }
  private readonly Property _name;
  [RequiredValidator("必須")]
  public Property Name
  {
    get { return this._name; }
  }
  public Data() : base()
  {
    this._id = new Property("Id", base.ValidateAction);
    this._name = new Property("Name", base.ValidateAction);
  }
}
// View
public Page2()
{
  InitializeComponent();

  var d = new Data();
  d.ResumeValidation();
  this.DataContext = d;
  d.Initialize();
}

こんな感じに出来た。


【参考にしたサイト】
http://japan.internet.com/developer/20090421/26.html
http://blogs.wankuma.com/rti/archive/2009/04/24/172035.aspx
http://blogs.wankuma.com/kazuki/archive/2009/03/21/170005.aspx