私の疑問は単純です。WPF 4.5 でこの INotifyDataErrorInfo を使用して例外を表示するにはどうすればよいですか?
私はMVVMを使用しています:
これが私の見解の一部です
<TextBox MinHeight="50"
Text="{Binding Person.Name, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}"
そして、ここに私のモデルクラスがあります。@ 文字を設定した Validate メソッドが例外をスローすることを確認します。
public class Person : DomainObject
{
private string _name;
public string Name
{
get
{
return this._name;
}
set
{
if (this._name != value)
{
this.ValidateProperty("Name", value);
this._name = value;
this.RaisePropertyChanged("Name");
}
}
}
}
protected override void ValidateProperty(string propertyName, object value)
{
if (propertyName == "Name")
{
var errors = new List<string>();
var response = value as string;
if (string.IsNullOrEmpty(response))
{
errors.Add("The value cannot be null or empty");
}
else if (response == "@")
{
throw new Exception("@");
}
this.ErrorsContainer.SetErrors(propertyName, errors);
}
else
{
base.ValidateProperty(propertyName, value);
}
}
それが起こると、それは本当にプログラムを停止します..そして、私の知る限り、Silverlightではこれは起こりません.