xaml –> UIElement:
public static FrameworkElement GetElementFromXamlString(string xaml)
{
StringReader stringReader = new StringReader(xaml);
XmlReaderSettings readersettings = new XmlReaderSettings();
readersettings.ConformanceLevel = ConformanceLevel.Fragment;
XmlReader xmlReader = XmlReader.Create(stringReader, readersettings);
FrameworkElement element = (FrameworkElement)System.Windows.Markup.XamlReader.Load(xmlReader);
return element;
}
UIElement –>xaml:
string str = System.Windows.Markup.XamlWriter.Save(element);