XamlReader.Load XamlReader.Load XamlReader.Load XamlReader.Load Method

Definition

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

Overloads

Load(Stream) Load(Stream) 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) Load(XamlReader) Load(XamlReader) 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) Load(XmlReader) Load(XmlReader) 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, ParserContext) Load(Stream, ParserContext) 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(Stream) Load(Stream) 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
Parameters
stream
Stream Stream Stream Stream

The XAML to load, in stream form.

Returns

The object at the root of the created object tree.

Exceptions

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

Load(XamlReader) Load(XamlReader) Load(XamlReader) 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 XamlReader XamlReader 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

Remarks

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

Load(XmlReader) Load(XmlReader) Load(XmlReader) 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 XmlReader XmlReader 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

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

Load(Stream, ParserContext) Load(Stream, ParserContext) 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
Parameters
stream
Stream Stream Stream Stream

The stream that contains the XAML input to load.

parserContext
ParserContext ParserContext ParserContext ParserContext

Context information used by the parser.

Returns

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

Exceptions
See Also

Applies to