Xaml​Reader.​Load Method

Definition

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(​Xaml​Reader)

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

Load(​Xml​Reader)

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

Load(​Stream, ​Parser​Context)

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

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 object Load (System.IO.Stream stream);
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)

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 object Load (System.Xaml.XamlReader reader);
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.

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 object Load (System.Xml.XmlReader reader);
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)

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 object Load (System.IO.Stream stream, System.Windows.Markup.ParserContext parserContext);
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.