Op Englesch liesen Editéieren

Deelen iwwer


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.

C#
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.

C#
// 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);

See also

Applies to

.NET Framework 4.8.1 an aner Versiounen
Produkt Versiounen
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Load(XamlReader)

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

C#
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.

Applies to

.NET Framework 4.8.1 an aner Versiounen
Produkt Versiounen
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Load(XmlReader)

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

C#
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.

C#
// 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);

See also

Applies to

.NET Framework 4.8.1 an aner Versiounen
Produkt Versiounen
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Load(Stream, Boolean)

C#
public static object Load(System.IO.Stream stream, bool useRestrictiveXamlReader);

Parameters

stream
Stream
useRestrictiveXamlReader
Boolean

Returns

Applies to

Windows Desktop 10 an aner Versiounen
Produkt Versiounen
Windows Desktop 5, 6, 7, 8, 9, 10

Load(Stream, ParserContext)

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

C#
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.

See also

Applies to

.NET Framework 4.8.1 an aner Versiounen
Produkt Versiounen
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Load(XmlReader, Boolean)

C#
public static object Load(System.Xml.XmlReader reader, bool useRestrictiveXamlReader);

Parameters

reader
XmlReader
useRestrictiveXamlReader
Boolean

Returns

Applies to

Windows Desktop 10 an aner Versiounen
Produkt Versiounen
Windows Desktop 5, 6, 7, 8, 9, 10

Load(Stream, ParserContext, Boolean)

C#
public static object Load(System.IO.Stream stream, System.Windows.Markup.ParserContext parserContext, bool useRestrictiveXamlReader);

Parameters

stream
Stream
parserContext
ParserContext
useRestrictiveXamlReader
Boolean

Returns

Applies to

Windows Desktop 10 an aner Versiounen
Produkt Versiounen
Windows Desktop 5, 6, 7, 8, 9, 10