BeginEdit resets Model properties: ViewModelDetailBase

Apr 23, 2012 at 7:49 AM

I am not sure why this is happening but when I run BeginEdit() on the MyViewModelDetailBase, it resets all the Model properties to either zero or NaN. I get back the values if I click the Cancel button in the child window. Looks like something is happening when making a copy/clone.

I am still using Silverlight 4 and NOT using RIA services.

Any help and guidance is appreciated.

Apr 26, 2012 at 9:06 AM

Should have read the documentation in detail where it says:

"The Clone and CopyValuesTo methods are implemented as extension methods in the Extensions class and can be brought into scope by inserting a using directive for the namespace, SimpleMvvmToolkit.ModelExtensions.  Clone uses the DataContractSerializer to serialize the object to and from a memory stream. It will work with entities that do not have the [DataContract] attribute by serializing all public properties."

I had [DataContract] attribute in my model and so I am guessing this was the issue. Removed it and now its working fine.

Coordinator
Apr 26, 2012 at 1:25 PM
Fantastic. You could keep the DataContract attribute, but you would need to add DataMember attributes to each property. Easier to just leave all the attributes out though.