2
在.NET 4.0中對XAML序列化堆棧進行了相當多的更改。其中一個變化是,當你序列化一個UserControl時,你不僅得到了控制本身,而且還得到了它的所有孩子。將用戶控件序列化爲xaml,但不是子項?
var sb = new StringBuilder();
var writer = XmlWriter.Create(sb, new XmlWriterSettings
{
Indent = true,
ConformanceLevel = ConformanceLevel.Fragment,
OmitXmlDeclaration = true
});
var mgr = new XamlDesignerSerializationManager(writer);
mgr.XamlWriterMode = XamlWriterMode.Expression;
System.Windows.Markup.XamlWriter.Save(this, mgr);
return sb.ToString();
,而不是領,例如,
<MyUserControl
xmlns="clr-namespace:MyNamespace"
SomeProperty="Add ten thousand child controls" />
你現在得到
<MyUserControl
xmlns="clr-namespace:MyNamespace"
SomeProperty="Add ten thousand child controls">
<StackPanel xmlns="http://microsoft.com/something/xaml/dude">
<TextBlock Text="Child Control ONE!"/>
<TextBlock Text="Child Control TWO!"/>
<TextBlock Text="Child Control THREE!"/>
<!--WTMFH?-->
<TextBlock Text="Child Control TEN FRIGGEN THOUSAND!"/>
</StackPanel>
</MyUserControl/>
我怎樣才能恢復這種行爲回到原來的方法是什麼?