を使用して WPF で基本的なデータ検証サンプルを実行したいのですValidatesOnException
が、単に機能せず、viewmodel
スローするとすぐValidationException
にプログラムがクラッシュし、「ValidationException was unhandled by user code 」と表示されます。
私のビューモデルは
public class MainViewModel : INotifyPropertyChanged
{
//INotifyPropertyChaned implementation
//////////////////////////////////////
private string stringValue;
public string StringValue
{
get { return stringValue; }
set
{
if (value.Length > 6)
{
//The below line throws unhandled exception error??
throw new ValidationException(String.Format("Value's length is greater than {0}.", value.Length));
}
stringValue = value;
this.OnPropertyChanged("StringValue");
}
}
}
私のXAMLは
<StackPanel x:Name="LayoutRoot" Background="White">
<TextBox x:Name="radMaskedTextInput1"
Width="200"
Margin="10"
Text="{Binding Path=StringValue, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>