Skip to content

Instantly share code, notes, and snippets.

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
You can’t perform that action at this time.