2009-04-23 42 views

回答

3

這說明你的整個生命週期(從控制到XAML回控制)。 如您所見,

string s = XamlWriter.Save(value); 

是您可能關心的有趣部分。

/// <summary> 
    /// Clones a given UIElement. Please note that any events, animations, etc 
    /// on the source item may not carry over to the cloned object. 
    /// </summary> 
    /// <param name="value">UIElement to clone.</param> 
    /// <returns>A shallow clone of the source element.</returns> 
    public static UIElement CloneUIElement(UIElement value) 
    { 
     if (value == null) 
     { 
      return null; 
     } 

     string s = XamlWriter.Save(value); 
     StringReader stringReader = new StringReader(s); 
     XmlReader xmlReader = XmlTextReader.Create(stringReader, new XmlReaderSettings()); 
     return (UIElement)XamlReader.Load(xmlReader); 
    } 
+0

這完美地工作。而且速度也非常快。謝謝! – JRobbers 2009-04-23 21:08:59

相關問題