XamlWriter 類別

定義

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

public ref class XamlWriter abstract sealed
public static class XamlWriter
type XamlWriter = class
Public Class XamlWriter
繼承
XamlWriter

範例

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

// 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);
' Create the Button.
Dim originalButton As New Button()
originalButton.Height = 50
originalButton.Width = 100
originalButton.Background = Brushes.AliceBlue
originalButton.Content = "Click Me"

' Save the Button to a string.
Dim savedButton As String = XamlWriter.Save(originalButton)

' Load the button
Dim stringReader As New StringReader(savedButton)
Dim xmlReader As XmlReader = XmlReader.Create(stringReader)
Dim readerLoadButton As Button = CType(XamlReader.Load(xmlReader), Button)

備註

這個方法所啟用的串行化有一系列限制。 這是因為啟用串行化是明確運行時間,而且如果有任何) ,則無法存取原始 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 的輸出接著可用於序列化所提供的物件及其屬性。

適用於

另請參閱