Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jon-kim
Created June 6, 2017 19:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jon-kim/c209cb196d54ce9b8ad703ddc265c49e to your computer and use it in GitHub Desktop.
Save jon-kim/c209cb196d54ce9b8ad703ddc265c49e to your computer and use it in GitHub Desktop.
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