views:

235

answers:

3

Hi,

Does anyone know a good way to serialize a System.Windows.Shape (incl. Polygon, Circle, Triangle etc.) object so that it may be saved in a database?

I have tried to serialize it using BinaryFormatter but it throws an exception saying that it is not marked as serializable.

Thanks in advance for any help.

Cheers,

Nilu

A: 

Hi, As far as i know the problem with serialization with this kind of object come because the matrix class is not serializable but you can create you own classes lets say for Polygon it will have all the proparties for polygon ponts[] , color so on. But instead fo matri add array of int an The matrix has method to get array of int and create matrix from array. This way your class will be seriazlizable Best Regards, Iordan

IordanTanev
cheers :) I will try that method
Nilu
You can try make some kind of wraper class in fact you use standart class but when making save create you class get all info from standart class and serialize. When load make the opossite and it may do the trick
IordanTanev
+1  A: 

Instead of writing a bunch of wrappers, you can just associate serialization surrogates with the non-serializable types. The formatter infrastructure will use these surrogates to serialize and deserialize the types in question. See IFormatter.SurrogateSelector.

HTH, Kent

Kent Boogaart
any tutorial etc for this.. above my current silverlight skillset.
Vaibhav Garg
A: 

You can use XamlWriter to serialize shapes to XAML and save that to the database

Nir