Created
June 6, 2017 19:34
-
-
Save jon-kim/c209cb196d54ce9b8ad703ddc265c49e to your computer and use it in GitHub Desktop.
Clone WPF User Control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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