question

essamce avatar image
0 Votes"
essamce asked ·

copging UIElement

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 error8092-error.png


windows-wpf
error.png (107.2 KiB)
· 4
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I ca n’t reproduce the error in my sample with your methods. Could you give some details about how to use the controls and ResourceDictionary in your project or give a simple demo to reproduce the error?

1 Vote 1 ·

here is a repo
SoilProfile-temp.git


0 Votes 0 ·

I downloaded your project from the github, but I can’t run your project and find it is not a simple demo. Your project includes many other functions, could you provide a simple demo which only contain the copy function? This will reduce the work for analyze your question.

0 Votes 0 ·

im building wpf .netCore, using VS2019

0 Votes 0 ·

1 Answer

PeterFleischer-3316 avatar image
1 Vote"
PeterFleischer-3316 answered ·

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.

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

hi @PeterFleischer-3316
i don't how to do that, any help?

0 Votes 0 ·