Editare

Partajați prin


XamlWriter.Save Method

Definition

Returns XAML either directly or through an object intermediary that serializes the specified object.

Overloads

Save(Object)

Returns a XAML string that serializes the specified object and its properties.

Save(Object, Stream)

Saves XAML information into a specified stream to serialize the specified object and its properties.

Save(Object, TextWriter)

Saves XAML information as the source for a provided TextWriter object. The output of the TextWriter can then be used to serialize the provided object and its properties.

Save(Object, XamlDesignerSerializationManager)

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)

Saves XAML information as the source for a provided XmlWriter object. The output of the XmlWriter can then be used to serialize the provided object and its properties.

Save(Object)

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

Parameters

obj
Object

The element to be serialized. Typically, this is the root element of a page or application.

Returns

A XAML string that can be written to a stream or file. The logical tree of all elements that fall under the provided obj element will be serialized.

Exceptions

obj is null.

The application is not running in full trust.

Examples

The following example serializes a Button into a string using the XamlWriter class. 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)

Remarks

The serialization enabled by this method has a series of limitations. 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). For details, see Serialization Limitations of XamlWriter.Save.

Calling Save is not permitted when running in partial trust.

See also

Applies to

Save(Object, Stream)

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
Public Shared Sub Save (obj As Object, stream As Stream)

Parameters

obj
Object

The element to be serialized. Typically, this is the root element of a page or application.

stream
Stream

Destination stream for the serialized XAML information.

Exceptions

obj or stream is null.

The application is not running in full trust.

Examples

The following example serializes a Button into a MemoryStream using the XamlWriter class. 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)

Remarks

The serialization enabled by this method has a series of limitations. 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). For details, see Serialization Limitations of XamlWriter.Save.

Calling Save is not permitted when running in partial trust.

See also

Applies to

Save(Object, TextWriter)

Saves XAML information as the source for a provided TextWriter object. 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)

Parameters

obj
Object

The element to be serialized. Typically, this is the root element of a page or application.

writer
TextWriter

A TextWriter instance as the destination where the serialized XAML information is written.

Exceptions

obj or writer is null.

The application is not running in full trust.

Remarks

The serialization enabled by this method has a series of limitations. 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). For details, see Serialization Limitations of XamlWriter.Save.

Calling Save is not permitted when running in partial trust.

See also

Applies to

Save(Object, XamlDesignerSerializationManager)

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)

Parameters

obj
Object

The element to be serialized. Typically, this is the root element of a page or application.

manager
XamlDesignerSerializationManager

A custom serialization implementation.

Exceptions

obj or manager is null.

The application is not running in full trust.

Remarks

The serialization enabled by this method has a series of limitations. 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). For details, see Serialization Limitations of XamlWriter.Save.

Calling Save is not permitted when running in partial trust.

See also

Applies to

Save(Object, XmlWriter)

Saves XAML information as the source for a provided XmlWriter object. 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
Public Shared Sub Save (obj As Object, xmlWriter As XmlWriter)

Parameters

obj
Object

The element to be serialized. Typically, this is the root element of a page or application.

xmlWriter
XmlWriter

Writer to use to write the serialized XAML information.

Exceptions

obj or xmlWriter is null.

The application is not running in full trust.

Remarks

The serialization enabled by this method has a series of limitations. 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). For details, see Serialization Limitations of XamlWriter.Save.

Calling Save is not permitted when running in partial trust.

See also

Applies to