Problem serializing aCanvas to a file..
Last post 05-12-2008 5:19 AM by le kurde. 3 replies.
Sort Posts:
05-08-2008 9:14 AM
Problem serializing aCanvas to a file..

Hi everybody! 

I've got a Silverlight project where an user can custuming a canva by adding some controls an photos on it.

Now I would like to save the canvas on a xaml file. But before i making some test.

For that, i using an asp web service (with soap) where a methode taking an object and convert it to a xaml string with XamlWriter.Save.

On Silverlight side, I  have made an UserControl named TestSerialization whith [DataContract] attribute before it. In the control, I've got an canvas filled with a color. So, in the TestSerialization.g.cs file, i've put [DataMember] just before it.

here is now my Saving method on Silverlight-side :

NisinServiceProxy.NisinBaseWebServiceSoapClient npc = new Gestion_Canevas_beta_1.NisinServiceProxy.NisinBaseWebServiceSoapClient();
            npc.SauvegarderCanevasXAMLCompleted += new EventHandler<Gestion_Canevas_beta_1.NisinServiceProxy.SauvegarderCanevasXAMLCompletedEventArgs>(npc_SauvegarderCanevasXAMLCompleted);
            List<Type> lt = new List<Type>();
            //lt.Add(typeof(Canvas));
            lt.Add(typeof(TestSerialisation));
            lt.Add(typeof(XmlWriter));
            lt.Add(typeof(Canvas));
            lt.Add(typeof(Stream));
            DataContractSerializer dcs = new DataContractSerializer(typeof(TestSerialisation),lt);
            s = Stream.Null;
           
            XmlWriter xmlw=XmlWriter.Create(s);
            try
            {
                dcs.WriteObject(xmlw, test); //=> test is a TestSerialisation object.............I've already try with just s(the stream) without xmlWriter but it's the same effect
                npc.SauvegarderCanevasXAMLAsync(xmlw);
            }
            catch (InvalidDataContractException ex)
            {
                mlg.AfficherMessage(ex.Message);
            }
           

 here is the declaration of the elements:

 [DataMember]
public Stream s = null;

public TestSerialisation test = new TestSerialisation(); 

 I've work on this since 2 days and I doesn't find any exemple of it on the web, there is a lot of exemple on other context(WPF, ect..) but not in Silverlight with a web service...

Please help me!! I"m starting to get crazy! ^^

 

le kurde

Joined on 03-14-2008
Liege, Belgium
Posts 28
05-11-2008 11:18 PM
Re: Problem serializing aCanvas to a file..

Hello:

  XamlWriter is not supported yet. You may refer to this article. Though it's for 1.1 alpha you may do some modification to make it work in Silverlight 2 Betar 1 (see comment):

http://weblogs.asp.net/mehrantoosi/archive/2008/03/03/silverlight-s-xamlwriter.aspx

Regards

Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Allen Chen – MSFT

Joined on 03-16-2007
Posts 717
05-11-2008 11:28 PM
Re: Problem serializing aCanvas to a file..

Hello,

XamlWriter is not supported in Silverlight 2 beta1. 

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Best Regards,
Michael Sync

Blog : http://michaelsync.net
Feed : http://michaelsync.net/feed

mchlSync

Joined on 09-16-2005
Singapore
Posts 2,021
05-12-2008 5:19 AM
Re: Problem serializing aCanvas to a file..

 

Hum.....I already KNOW that ^^ that's why I want to use a webservice the probleme here is a serialization problem... and in my code ..juste look better..it's XMLWriter ^^

I know that my English it's not the best but....

le kurde

Joined on 03-14-2008
Liege, Belgium
Posts 28