XamlWriter 類別

定義

提供單一靜態的 Save 方法 (多重多載),該方法可用於受限制的 XAML 序列化 (Serialization),將提供的執行階段物件序列化為 XAML 標記。

C#
public static class XamlWriter
繼承
XamlWriter

範例

下列範例會使用 XamlWriter 類別將 串行化Button為字串。 然後使用 類別上的XamlReader靜態Load方法,將字串還原串行化回 Button

C#
// Create the Button.
Button originalButton = new Button();
originalButton.Height = 50;
originalButton.Width = 100;
originalButton.Background = Brushes.AliceBlue;
originalButton.Content = "Click Me";

// Save the Button to a string.
string savedButton = XamlWriter.Save(originalButton);

// Load the button
StringReader stringReader = new StringReader(savedButton);
XmlReader xmlReader = XmlReader.Create(stringReader);
Button readerLoadButton = (Button)XamlReader.Load(xmlReader);

備註

這個方法所啟用的串行化有一系列限制。 這是因為啟用串行化是明確運行時間,而且如果有任何) ,則無法存取原始 XAML (中可能的設計時間資訊。 如需詳細資訊,請參閱 XamlWriter.Save 的串行化限制

在部分信任中執行時,不允許呼叫 Save 。 這包括來自 XBAP 的 。

方法

Save(Object)

傳回可序列化指定之物件及其屬性的 XAML 字串。

Save(Object, Stream)

將 XAML 資訊儲存到指定的資料流,以序列化指定的物件及其屬性。

Save(Object, TextWriter)

將 XAML 資訊另存為所提供之 TextWriter 物件的來源。 TextWriter 的輸出接著可用於序列化所提供的物件及其屬性。

Save(Object, XamlDesignerSerializationManager)

將 XAML 資訊儲存到自訂序列化程式。 序列化程式的輸出接著可用於序列化所提供的物件及其屬性。

Save(Object, XmlWriter)

將 XAML 資訊另存為所提供之 XmlWriter 物件的來源。 XmlWriter 的輸出接著可用於序列化所提供的物件及其屬性。

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另請參閱