Hi, loading a XAML with resources you add resource and you get conflict with existing resources. You must copy XAML without resources and include resources only once.
copging UIElement
essamce
621
Reputation points
hi,
i'm trying to copy UIElement, and it always gives me the same error.
here method i'm trying:
public static UIElement cloneElement(UIElement orig)
{
if (orig == null)
{
return (null);
}
var s = System.Windows.Markup.XamlWriter.Save(orig);
var stringReader = new System.IO.StringReader(s);
var xmlReader = System.Xml.XmlTextReader.Create(stringReader, new System.Xml.XmlReaderSettings());
return (UIElement)System.Windows.Markup.XamlReader.Load(xmlReader);
}
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;
}
here is the error
1 answer
Sort by: Most helpful
-
Peter Fleischer (former MVP) 19,331 Reputation points
2020-05-11T10:16:14.627+00:00