15. ②Exception
WPF 4 Silverlight 4 Windows Phone OS 7.0
VSUG DAY 2010.12.11 15
16. ②Exception
<TextBox Text="{Binding AccountName, ValidatesOnExceptions=
True}"/>
WPF 4 Silverlight 4 Windows Phone OS 7.0
バインディング
TextBox オブジェクト Customer
ValidatesOnExceptions=True AccountName
Text プロパティ
プロパティ 検証処理
例外をスロー
VSUG DAY 2010.12.11 16
17. Exception(例外)によるエラー通知
public string AccountName
{
get { return _accountName; }
set
{
if (string.IsNullOrEmpty((string)value))
{
throw new Exception("必須入力項目です。");
}
else if (!Regex.IsMatch((string)value, "^[0-9A-Za-z]{5,12}$"))
{
throw new Exception("半角英数字5文字以上12文字以下で入力して
ください。");
}
_accountName = value;
}
} WPF 4 Silverlight 4 Windows Phone OS 7.0
VSUG DAY 2010.12.11 17
59. まとめ
検証
① ValidationRule
② Exception
③ IDataErrorInfo
④ INotifyDataErrorInfo
アクション
a. ErrorTemplate添付プロパティ
b. VisualStateManager(VSM)
c. HasError添付プロパティ(プロパティトリガー)
d. イベント
VSUG DAY 2010.12.11 59
69. 検証属性の自動適用
Silverlight 4
VSUG DAY 2010.12.11 69
70. 検証属性の自動適用
Silverlight 4のDataGrid
データ注釈を使用したデータ クラスのカスタマイズ
http://msdn.microsoft.com/ja-jp/library/dd901590.aspx
WCF RIA Services
How to: Validate Data
http://msdn.microsoft.com/en-us/library/ee707335.aspx
VSUG DAY 2010.12.11 70
77. 編集トランザクション
Private Sub SubmitButton_Click(ByVal sender As System.Object,
ByVal e As System.Windows.RoutedEventArgs)
If LayoutRoot.BindingGroup.CommitEdit() Then
MessageBox.Show("登録されました。")
LayoutRoot.BindingGroup.BeginEdit()
End If
End Sub
Private Sub CancelButton_Click(ByVal sender As System.Object,
ByVal e As System.Windows.RoutedEventArgs)
LayoutRoot.BindingGroup.CancelEdit()
LayoutRoot.BindingGroup.BeginEdit()
End Sub
WPF 4
VSUG DAY 2010.12.11 77