Hello,
I've been struggling for days to implement a DataGrid using the MVVM pattern that sets DataGrid.CanUserAddRows=true and uses Binding.ValidationRules for validation. Unfortunately this has lead down multiple rabbit-holes that dead-end.
Just one example: Why do validation rules not fire when a the user clicks on a new row and then clicks away? No data changes, so there is no way to stop a blank row from being added to the collection backing the datagrid. I've taken multiple
tries at hacking correct behavior into the control at the code-behind level and using attached behaviors, but no approach seems to work 100% correctly and I get the feeling I'm missing something simple and/or important or there are bugs in the implementation
of the control in WPF.
And plese spare me the basics on binding - the problem isn't there. My collection class derives from and properly implements ObservableCollection<T>, IEditableObject
and my row class derives from and properly implements
INotifyPropertyChanged, IEditableObject, IEditableObjectProperty Believe me, I have wasted a lot of time on this.
Rather than go into the multiple issues involved could someone at Microsoft please provide a complete, reasonably clean code sample project that demonstrates how to implement a DataGrid that implements in-place (preferrably one-click) data editing, in-place row adding (aka CauUerAddRows), and a per-row delete button, using MVVM Binding and that correctly calls into the ViewModel for validation?
Thanks in advance.
Some references that might be helpful:
http://stackoverflow.com/questions/4106056/wpf-datagrid-handling-canuseraddrows-true-cleanly-with-mvvm
http://stackoverflow.com/questions/2060046/wpf-datagrid-allow-user-to-add-rows
http://blogs.msdn.com/b/vinsibal/archive/2008/05/20/wpf-3-5-sp1-feature-ieditablecollectionview.aspx
http://stackoverflow.com/questions/9786612/how-to-get-datagrideditaction-cancel
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/1665e197-f7df-476f-a139-061f871b0434/
http://www.codeproject.com/Articles/30905/WPF-DataGrid-Practical-Examples#validation
http://wpf.codeplex.com/discussions/34847
http://stackoverflow.com/questions/4833100/updatesourcetrigger-propertychanged-equivalent-for-a-windows-phone-7-textbox
http://blogs.msdn.com/b/vinsibal/archive/2008/11/05/wpf-datagrid-new-item-template-sample.aspx
http://www.a2zdotnet.com/View.aspx?Id=135#.UVOhIVeH98E
http://wpf.codeplex.com/discussions/60355?ProjectName=wpf
http://stackoverflow.com/questions/10388466/wpf-datagrid-celleditended-event
http://stackoverflow.com/questions/8877391/wpf-datagrid-celleditending-c-sharp
http://www.codeproject.com/Articles/15239/Validation-in-Windows-Presentation-Foundation
http://stackoverflow.com/questions/6598241/wpf-datagrid-new-row-validation