开发者

WPF validation 'before' setting value or issuing command

G开发者_StackOverflowreetings,

I am relatively new to WPF and have an issue relating to validation with DataGrid control. I have read this article (http://msdn.microsoft.com/en-us/magazine/ff714593.aspx) which covers three different ways to validate, but none of them seem to address how to prevent setting a value or calling a undo/redo command before all validation is carried out.

I want to ensure that only positive numbers can be entered into the cells. I have set a validation rule that checks if the cell contains a negative number, and I handle the DataGrid's CellEditEnding event to know when to actually change the number used in the model layer. The problem is that CellEditEnding is called before the validation rule. By the time the validation rule catches the problem, the number in the model has already been set. What I need is CellEditEnded, but it appears this event only exist in the Silvelight version of DataGrid.

Any ideas?

Thanks


The datagrid is a tricky one, and pretty complex. I think in this case, I might try altering the "setter" for the property that this is bound to. Throw an exception if the user enters an invalid value. The datagrid supports showing the invalid cells with a validation error (red border) so that the user sees which cells / rows have issues.

It's not ideal, but it might work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜