Home > English > Cloning an element on the Visual Tree

Cloning an element on the Visual Tree

Sometime is it is necessary to make a copy of an element on the visual tree and the insert it somewhere for use.  Unfortunately, copying an element and inserting it in another location is not allowed.  Instead of doing this all from scratch and creating a new instance of the element that you want.  You can always resort to other techniques.  I will be presenting one such technique.  The approach I use involves using the DataContractSerializer.  This is a built-in class in the System.Runtime.Serialization namespace.  It is very powerful and is used ubiquitously throughout WCF.  Here is a screenshot of the CloneFactory I created:

As you can tell, it is a very succinct and short piece of code.  Yet this code is very powerful.  It does in memory serialization and only as one level deep.  You could always refactor this a little to make it recursive or to define the number of levels deep you wished to copy.  This would allow you to have deep copy to the level that you so desired.

Hope this helps….

Advertisements
Categories: English Tags: ,
  1. August 28, 2011 at 11:41 am

    Genuinely instructive and superb structure of articles, now that’s user friendly (:.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: