Serializing Shape objects in WPF
-
11-09-2019 - |
Question
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
Solution
You can use XamlWriter to serialize shapes to XAML and save that to the database
OTHER TIPS
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
.
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