Skip to content

Instantly share code, notes, and snippets.

@jon-kim
Created June 6, 2017 19:34
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Clone WPF User Control
public static class ExtensionMethods
{
public static T XamlClone<T>(this T original) where T : class
{
if (original == null)
return null;
object clone;
using (var stream = new MemoryStream())
{
XamlWriter.Save(original, stream);
stream.Seek(0, SeekOrigin.Begin);
clone = XamlReader.Load(stream);
}
if (clone is T)
return (T)clone;
else
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment