本文介绍了有什么方法可以提取底层Xaml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

无论如何都可以从控件中提取底层 xaml.

Is there anyway to extract the underlying xaml from a control.

IE.我有一个名为 fooBox 的文本框.我可以在运行时从代表文本框的文本框中获取 xaml 吗?

IE. I have a textbox named fooBox. Can I get xaml back from the textbox at runtime that represents the textbox?

推荐答案

这向您展示了完整的生命周期(从控件到 XAML 再到控件).如您所见,

This shows you the full lifecycle (from control to XAML back to control).As you can see,

string s = XamlWriter.Save(value);

是您可能关心的有趣部分.

is the interesting part you might care about.

    /// <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);
    }

这篇关于有什么方法可以提取底层Xaml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 12:31