XamlWriter.Save 方法

定义

直接或通过用于序列化指定对象的中间对象返回 XAML。Returns XAML either directly or through an object intermediary that serializes the specified object.

重载

Save(Object)

返回用于序列化指定对象及其属性的 XAML 字符串。Returns a XAML string that serializes the specified object and its properties.

Save(Object, Stream)

将 XAML 信息保存到指定流中,以便序列化指定对象及其属性。Saves XAML information into a specified stream to serialize the specified object and its properties.

Save(Object, TextWriter)

将 XAML 信息保存为所提供的 TextWriter 对象的源。Saves XAML information as the source for a provided TextWriter object. 然后,可以使用 TextWriter 的输出对所提供的对象及其属性进行序列化。The output of the TextWriter can then be used to serialize the provided object and its properties.

Save(Object, XamlDesignerSerializationManager)

将 XAML 信息保存到自定义序列化程序中。Saves XAML information into a custom serializer. 然后,可以使用该序列化程序的输出来序列化提供的对象及其属性。The output of the serializer can then be used to serialize the provided object and its properties.

Save(Object, XmlWriter)

将 XAML 信息保存为所提供的 XmlWriter 对象的源。Saves XAML information as the source for a provided XmlWriter object. 然后,可以使用 XmlWriter 的输出对所提供的对象及其属性进行序列化。The output of the XmlWriter can then be used to serialize the provided object and its properties.

Save(Object)

返回用于序列化指定对象及其属性的 XAML 字符串。Returns a XAML string that serializes the specified object and its properties.

public:
 static System::String ^ Save(System::Object ^ obj);
public static string Save (object obj);
static member Save : obj -> string
Public Shared Function Save (obj As Object) As String

参数

obj
Object

要序列化的元素。The element to be serialized. 通常,这是页面或应用程序的根元素。Typically, this is the root element of a page or application.

返回

可以写入流或文件的 XAML 字符串。A XAML string that can be written to a stream or file. 将序列化位于提供的 obj 元素下面的所有元素的逻辑树。The logical tree of all elements that fall under the provided obj element will be serialized.

异常

objnullobj is null.

应用程序未在完全信任环境中运行。The application is not running in full trust.

示例

下面的示例XamlWriter使用类Button将序列化为字符串。The following example serializes a Button into a string using the XamlWriter class. 然后, Button使用XamlReader类上的静态Load方法, 将字符串反序列化为。The string is then deserialized back into a Button using the static Load method on the XamlReader class.

// 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)

注解

此方法启用的序列化具有一系列限制。The serialization enabled by this method has a series of limitations. 这是因为启用序列化的是显式运行时, 不能访问原始 XAML (如果有) 中可能的设计时信息。This is because the serialization enabled is explicitly run-time, and does not have access to possible design-time information in the original XAML (if any). 有关详细信息, 请参阅system.windows.markup.xamlwriter.save 的序列化限制For details, see Serialization Limitations of XamlWriter.Save.

Save部分信任环境中运行时, 不允许调用。Calling Save is not permitted when running in partial trust.

另请参阅

Save(Object, Stream)

将 XAML 信息保存到指定流中,以便序列化指定对象及其属性。Saves XAML information into a specified stream to serialize the specified object and its properties.

public:
 static void Save(System::Object ^ obj, System::IO::Stream ^ stream);
public static void Save (object obj, System.IO.Stream stream);
static member Save : obj * System.IO.Stream -> unit

参数

obj
Object

要序列化的元素。The element to be serialized. 通常,这是页面或应用程序的根元素。Typically, this is the root element of a page or application.

stream
Stream

序列化 XAML 信息的目标流。Destination stream for the serialized XAML information.

异常

objstreamnullobj or stream is null.

应用程序未在完全信任环境中运行。The application is not running in full trust.

示例

下面的示例Button MemoryStream使用XamlWriter类将序列化到中。The following example serializes a Button into a MemoryStream using the XamlWriter class. 然后, Button使用XamlReader类上的静态Load方法将流反序列化为。The stream is then deserialized back into a Button using the static Load method on the XamlReader class.

// 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)

注解

此方法启用的序列化具有一系列限制。The serialization enabled by this method has a series of limitations. 这是因为启用序列化的是显式运行时, 不能访问原始 XAML (如果有) 中可能的设计时信息。This is because the serialization enabled is explicitly run-time, and does not have access to possible design-time information in the original XAML (if any). 有关详细信息, 请参阅system.windows.markup.xamlwriter.save 的序列化限制For details, see Serialization Limitations of XamlWriter.Save.

Save部分信任环境中运行时, 不允许调用。Calling Save is not permitted when running in partial trust.

另请参阅

Save(Object, TextWriter)

将 XAML 信息保存为所提供的 TextWriter 对象的源。Saves XAML information as the source for a provided TextWriter object. 然后,可以使用 TextWriter 的输出对所提供的对象及其属性进行序列化。The output of the TextWriter can then be used to serialize the provided object and its properties.

public:
 static void Save(System::Object ^ obj, System::IO::TextWriter ^ writer);
public static void Save (object obj, System.IO.TextWriter writer);
static member Save : obj * System.IO.TextWriter -> unit
Public Shared Sub Save (obj As Object, writer As TextWriter)

参数

obj
Object

要序列化的元素。The element to be serialized. 通常,这是页面或应用程序的根元素。Typically, this is the root element of a page or application.

writer
TextWriter

作为写入序列化 XAML 信息的目标的 TextWriter 实例。A TextWriter instance as the destination where the serialized XAML information is written.

异常

objwriternullobj or writer is null.

应用程序未在完全信任环境中运行。The application is not running in full trust.

注解

此方法启用的序列化具有一系列限制。The serialization enabled by this method has a series of limitations. 这是因为启用序列化的是显式运行时, 不能访问原始 XAML (如果有) 中可能的设计时信息。This is because the serialization enabled is explicitly run-time, and does not have access to possible design-time information in the original XAML (if any). 有关详细信息, 请参阅system.windows.markup.xamlwriter.save 的序列化限制For details, see Serialization Limitations of XamlWriter.Save.

Save部分信任环境中运行时, 不允许调用。Calling Save is not permitted when running in partial trust.

另请参阅

Save(Object, XamlDesignerSerializationManager)

将 XAML 信息保存到自定义序列化程序中。Saves XAML information into a custom serializer. 然后,可以使用该序列化程序的输出来序列化提供的对象及其属性。The output of the serializer can then be used to serialize the provided object and its properties.

public:
 static void Save(System::Object ^ obj, System::Windows::Markup::XamlDesignerSerializationManager ^ manager);
public static void Save (object obj, System.Windows.Markup.XamlDesignerSerializationManager manager);
static member Save : obj * System.Windows.Markup.XamlDesignerSerializationManager -> unit
Public Shared Sub Save (obj As Object, manager As XamlDesignerSerializationManager)

参数

obj
Object

要序列化的元素。The element to be serialized. 通常,这是页面或应用程序的根元素。Typically, this is the root element of a page or application.

manager
XamlDesignerSerializationManager

自定义序列化实现。A custom serialization implementation.

异常

objmanagernullobj or manager is null.

应用程序未在完全信任环境中运行。The application is not running in full trust.

注解

此方法启用的序列化具有一系列限制。The serialization enabled by this method has a series of limitations. 这是因为启用序列化的是显式运行时, 不能访问原始 XAML (如果有) 中可能的设计时信息。This is because the serialization enabled is explicitly run-time, and does not have access to possible design-time information in the original XAML (if any). 有关详细信息, 请参阅system.windows.markup.xamlwriter.save 的序列化限制For details, see Serialization Limitations of XamlWriter.Save.

Save部分信任环境中运行时, 不允许调用。Calling Save is not permitted when running in partial trust.

另请参阅

Save(Object, XmlWriter)

将 XAML 信息保存为所提供的 XmlWriter 对象的源。Saves XAML information as the source for a provided XmlWriter object. 然后,可以使用 XmlWriter 的输出对所提供的对象及其属性进行序列化。The output of the XmlWriter can then be used to serialize the provided object and its properties.

public:
 static void Save(System::Object ^ obj, System::Xml::XmlWriter ^ xmlWriter);
public static void Save (object obj, System.Xml.XmlWriter xmlWriter);
static member Save : obj * System.Xml.XmlWriter -> unit

参数

obj
Object

要序列化的元素。The element to be serialized. 通常,这是页面或应用程序的根元素。Typically, this is the root element of a page or application.

xmlWriter
XmlWriter

用于写入序列化的 XAML 信息的编写器。Writer to use to write the serialized XAML information.

异常

objxmlWriternullobj or xmlWriter is null.

应用程序未在完全信任环境中运行。The application is not running in full trust.

注解

此方法启用的序列化具有一系列限制。The serialization enabled by this method has a series of limitations. 这是因为启用序列化的是显式运行时, 不能访问原始 XAML (如果有) 中可能的设计时信息。This is because the serialization enabled is explicitly run-time, and does not have access to possible design-time information in the original XAML (if any). 有关详细信息, 请参阅system.windows.markup.xamlwriter.save 的序列化限制For details, see Serialization Limitations of XamlWriter.Save.

Save部分信任环境中运行时, 不允许调用。Calling Save is not permitted when running in partial trust.

另请参阅

适用于