Skip to main content

Microsoft Silverlight

Answered Question clone usercontrolRSS Feed

(0)

starsign
starsign

Member

Member

90 points

37 Posts

clone usercontrol

Hi,

 I want to make a clone of a usercontrol at runtime to get an exqact copy of it.  There seems to be no binaryformatter in Silverlight so I thought about using DataContractSerializer.  My code is below but I get an error when this is run within the usercontrol iteself (it does seem to work on a normal class) - the error says Type not serializable so my first guess is that the XAML may need a tag to allow it to be serialized?

 MemoryStream ms = new MemoryStream();

 

DataContractSerializer ser = new DataContractSerializer(typeof(MyUserControl));ser.WriteObject(ms, this);

 

XmlDictionaryReader reader = XmlDictionaryReader.CreateDictionaryReader(XmlDictionaryReader.Create(ms));

MyUserControl ctl = (MyUserControl)ser.ReadObject(reader);

reader.Close();

ms.Close();

 

Any help would be really appreciated.

 Thanks

tamirk
tamirk

Member

Member

100 points

23 Posts

Answered Question

Re: clone usercontrol

 You can use my "reflection" approach to create deep clone of UserControl.

Tamir http://khason.net
If your question was answered, mark the answer

starsign
starsign

Member

Member

90 points

37 Posts

Re: clone usercontrol

thanks - does that clone the contents of member variables from the code behind class too?

tamirk
tamirk

Member

Member

100 points

23 Posts

Re: Re: clone usercontrol

yes

Tamir http://khason.net
If your question was answered, mark the answer
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities