Question

I have a DevExpress DxGrid bound to an ObservableCollection of viewmodels (based on SimpleMvvmToolkit). The viewmodel has 2 properties exposed by itself (a string and a boolean) and a few other properties are exposed by its base class (ViewModelDetailBase), one of them is the model behind the viewmodel.

Everytime I use the grid to modify the contents of one of the properties (e.g. the boolean value), I get an error saying "The type xxx cannot be serialized.." (xxx is the type of the Model) followed by the suggestion to use DataContractAttribute to circomvent the issue. I am not sure how and where to look for a solution. Maybe I should read up on it, but why is serialization needed here??

Anyway, I hope you can shed a light on this. I'd appreciate some pointers to get me looking in the right direction.

edit: Since the situation is too intricate to post the relevant code here, I made a sandbox project that reproduces the error. You can find it via this WeTransfer link.

Best regards, ~Rob

Was it helpful?

Solution

Thanks to great help of the Simple MVVM Toolkit community I found out that the solution was simple.

In Simple MVVM Toolkit, A viewmodel needs to be serializable because it gets cloned. This is to easily roll-back data when an action is canceled. The reason my viewmodel could not be cloned whas because its "model" property was missing a default (parameter-less) constructor.

There's no need to decorate the viewmodel and its properties with [DataContract] or [DataMember].

I hope this helps others.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top