我正在编写一个创建代码的工具(例如:代码生成器)。但是,有以下方法删除Combobox 中的 Visible Column 绑定。(WPF) 方法:
public static string ConvertControlToString<T>(T orig)
{
StringBuilder outstr = new StringBuilder();
//this code need for right XML fomating
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.NamespaceHandling = NamespaceHandling.OmitDuplicates;
XamlDesignerSerializationManager dsm = new XamlDesignerSerializationManager(XmlWriter.Create(outstr, settings));
//this string need for turning on expression saving mode
dsm.XamlWriterMode = XamlWriterMode.Expression;
XamlWriter.Save(orig, dsm);
return outstr.ToString();
}
在这种方法中,我得出以下表达式。
panel.ContentXamlString = EditorHelper.ConvertControlToString(c.Content);
谢谢你。