Bewerken

Share via


XamlReader.Load Method

Definition

Reads XAML input and returns the root of the corresponding object tree.

Overloads

Load(Stream)

Reads the XAML input in the specified Stream and returns an Object that is the root of the corresponding object tree.

Load(XamlReader)

Reads the XAML input through a provided XamlReader and returns an object that is the root of the corresponding object tree.

Load(XmlReader)

Reads the XAML input in the specified XmlReader and returns an object that is the root of the corresponding object tree.

Load(Stream, Boolean)
Load(Stream, ParserContext)

Reads the XAML input in the specified Stream and returns an object that is the root of the corresponding object tree.

Load(XmlReader, Boolean)
Load(Stream, ParserContext, Boolean)

Load(Stream)

Reads the XAML input in the specified Stream and returns an Object that is the root of the corresponding object tree.

public:
 static System::Object ^ Load(System::IO::Stream ^ stream);
public static object Load (System.IO.Stream stream);
static member Load : System.IO.Stream -> obj
Public Shared Function Load (stream As Stream) As Object

Parameters

stream
Stream

The XAML to load, in stream form.

Returns

The object at the root of the created object tree.

Exceptions

stream is null.

Examples

The following example saves a Button into a MemoryStream using the XamlWriter class. The stream is then loaded 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)

See also

Applies to

Load(XamlReader)

Reads the XAML input through a provided XamlReader and returns an object that is the root of the corresponding object tree.

public:
 static System::Object ^ Load(System::Xaml::XamlReader ^ reader);
public static object Load (System.Xaml.XamlReader reader);
static member Load : System.Xaml.XamlReader -> obj
Public Shared Function Load (reader As XamlReader) As Object

Parameters

reader
XamlReader

A XamlReader object. This is expected to be initialized with input XAML.

Returns

The object that is the root of the created object tree.

Exceptions

reader is null.

Remarks

The input XamlReader can be Baml2006Reader. This is how you can load BAML at run time, or for localization tool purposes.

Applies to

Load(XmlReader)

Reads the XAML input in the specified XmlReader and returns an object that is the root of the corresponding object tree.

public:
 static System::Object ^ Load(System::Xml::XmlReader ^ reader);
public static object Load (System.Xml.XmlReader reader);
static member Load : System.Xml.XmlReader -> obj
Public Shared Function Load (reader As XmlReader) As Object

Parameters

reader
XmlReader

The XmlReader that has already loaded the XAML input to load in XML form.

Returns

The object that is the root of the created object tree.

Exceptions

reader is null.

Examples

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

See also

Applies to

Load(Stream, Boolean)

public:
 static System::Object ^ Load(System::IO::Stream ^ stream, bool useRestrictiveXamlReader);
public static object Load (System.IO.Stream stream, bool useRestrictiveXamlReader);
static member Load : System.IO.Stream * bool -> obj
Public Shared Function Load (stream As Stream, useRestrictiveXamlReader As Boolean) As Object

Parameters

stream
Stream
useRestrictiveXamlReader
Boolean

Returns

Applies to

Load(Stream, ParserContext)

Reads the XAML input in the specified Stream and returns an object that is the root of the corresponding object tree.

public:
 static System::Object ^ Load(System::IO::Stream ^ stream, System::Windows::Markup::ParserContext ^ parserContext);
public static object Load (System.IO.Stream stream, System.Windows.Markup.ParserContext parserContext);
static member Load : System.IO.Stream * System.Windows.Markup.ParserContext -> obj
Public Shared Function Load (stream As Stream, parserContext As ParserContext) As Object

Parameters

stream
Stream

The stream that contains the XAML input to load.

parserContext
ParserContext

Context information used by the parser.

Returns

The object that is the root of the created object tree.

Exceptions

stream is null.

-or-

parserContext is null.

See also

Applies to

Load(XmlReader, Boolean)

public:
 static System::Object ^ Load(System::Xml::XmlReader ^ reader, bool useRestrictiveXamlReader);
public static object Load (System.Xml.XmlReader reader, bool useRestrictiveXamlReader);
static member Load : System.Xml.XmlReader * bool -> obj
Public Shared Function Load (reader As XmlReader, useRestrictiveXamlReader As Boolean) As Object

Parameters

reader
XmlReader
useRestrictiveXamlReader
Boolean

Returns

Applies to

Load(Stream, ParserContext, Boolean)

public:
 static System::Object ^ Load(System::IO::Stream ^ stream, System::Windows::Markup::ParserContext ^ parserContext, bool useRestrictiveXamlReader);
public static object Load (System.IO.Stream stream, System.Windows.Markup.ParserContext parserContext, bool useRestrictiveXamlReader);
static member Load : System.IO.Stream * System.Windows.Markup.ParserContext * bool -> obj
Public Shared Function Load (stream As Stream, parserContext As ParserContext, useRestrictiveXamlReader As Boolean) As Object

Parameters

stream
Stream
parserContext
ParserContext
useRestrictiveXamlReader
Boolean

Returns

Applies to