无论如何,是否可以从控件中提取底层 xaml。
IE。我有一个名为 fooBox 的文本框。我可以在运行时从文本框获取代表文本框的 xaml 吗?
这向您展示了完整的生命周期(从控件到 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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)