&tag(WPF/DataGrid);
*目次 [#d41ba80f]
#contents
*参考情報 [#oa3ed1b7]
-[[WPF DataGrid Practical Examples]]…入門記事。
-[[WPF DataGrid – Committing changes cell-by-cell | Colin Eberhardt's Adventures in WPF:http://www.scottlogic.co.uk/blog/colin/2009/01/wpf-datagrid-committing-changes-cell-by-cell/]]
-[[Pasting content to new rows on the WPF DataGrid - Vincent Sibal's Blog - Site Home - MSDN Blogs:http://blogs.msdn.com/b/vinsibal/archive/2008/09/25/pasting-content-to-new-rows-on-the-wpf-datagrid.aspx]]…DataGridの新規行追加位置(NewItemPlaceHolder)にペーストするコード。
-[[Nigel Spencer's Blog: WPF DataGrid Tips:http://blog.spencen.com/2009/04/13/wpf-datagrid-tips.aspx]]
*DataGridTemplateColumn [#qc97e048]
**ユーザーコントロールを表示する [#b1206246]
-[[wpf - custom control in DataGridTemplateColumn - Stack Overflow:http://stackoverflow.com/questions/4536987/custom-control-in-datagridtemplatecolumn]]

*Validation [#na59d971]
**値入力ごとの検証 [#u8abbfb1]
DataGridColumnので設定する。以下の例ではValidatesOnDataErrorsがTrueなのでIDataErrorInfoを使って検証される。
 <DataGridTextColumn Width="100" Header="名前" Binding="{Binding Name, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"/>
**行全体の検証 [#ke5bb539]
RowValidationRulesにValidationRuleを設定する。
#pre{{
<DataGrid.RowValidationRules>
   <local:RowDataInfoValidationRule ValidationStep="UpdatedValue"/>
</DataGrid.RowValidationRules>
}}

*トラブルシューティング [#t9a37977]

**追加情報: 'DeferRefresh'は、AddNewトランザクションまたはEditItemトランザクションの実行中は許可されません。 [#d2c201d7]

***再現方法 [#ca582bcf]
-DataGridでセル編集中に、DataContextが切り替わると発生。
-例えばTabControlの上にDataGridを乗せタブ切り替えにともなってバインドされたデータが切り替わる場合に発生する。

#ref(cell.png)

#ref(error.png)
***解決方法 [#z8f2ed33]
-[[DataGrid exception on validation failure (DeferRefresh is not allowed...) | Microsoft Connect:https://connect.microsoft.com/VisualStudio/feedback/details/591125/datagrid-exception-on-validation-failure-deferrefresh-is-not-allowed]]
-上記リンクの回避策ではViewModelにIEditableObjectを実装し、DataGridに、DataGridRollbackOnUnfocusedBehaviourというビヘイビアーを定義する回避策が紹介されている。

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS