Läs på engelska Redigera

Dela via


XamlServices.Load Method

Definition

Loads source for a XAML reader and writes its output as an object graph.

Overloads

Load(Stream)

Loads a Stream source for a XAML reader and writes its output as an object graph.

Load(TextReader)

Creates a XAML reader from a TextReader, and returns an object graph.

Load(String)

Loads a Stream source for a XAML reader and returns an object graph.

Load(XamlReader)

Loads a specific XAML reader implementation and returns an object graph.

Load(XmlReader)

Loads a specific XML reader implementation and returns an object graph.

Load(Stream)

Loads a Stream source for a XAML reader and writes its output as an object graph.

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

Parameters

stream
Stream

The stream to load as input.

Returns

The object graph that is written as output.

Exceptions

stream is null.

Remarks

Different signatures for the Load(Stream) method specify different types of input for the source XAML. The Load(Stream) internal implementation first creates an XmlReader by calling Create(Stream) and then creates a new instance of a specialized XamlReader that processes the input.

In order for the Load(Stream) call to successfully create an object graph, the following must be true:

  • The source is well-formed and valid XML.

  • The source is valid XAML at the language level.

  • The XAML types that are specified in the source XAML must resolve to backing types in the relevant XAML namespaces. For example, XAML types for WPF namespaces can resolve to a WPF XAML namespace as specified in the XAML; the assemblies for WPF must be included in the project or available in the run time; and so on.

Viktigt

XamlServices is not the recommended XAML reading or XAML writing API set if you are processing Windows Presentation Foundation (WPF) types, or types based on WPF. For WPF usage, use System.Windows.Markup.XamlReader for reading or loading XAML; and System.Windows.Markup.XamlWriter for writing back XAML. These classes use System.Xaml APIs internally in their implementation; however, they also provide support for WPF-specific concepts that influence the nature of XAML reading and writing, such as optimizations for dependency properties.

Applies to

.NET Framework 4.8.1 och andra versioner
Produkt Versioner
.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(TextReader)

Creates a XAML reader from a TextReader, and returns an object graph.

C#
public static object Load(System.IO.TextReader textReader);

Parameters

textReader
TextReader

The TextReader to use as the basis for the created XmlReader.

Returns

The object graph that is returned.

Exceptions

textReader is null.

Remarks

In order to return the object graph, the textReader input should be constructed by using its relevant input. For example, it should pass a StringReader that is constructed by using a valid XAML-as-string input for the StringReader(String) constructor.

Applies to

.NET Framework 4.8.1 och andra versioner
Produkt Versioner
.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(String)

Loads a Stream source for a XAML reader and returns an object graph.

C#
public static object Load(string fileName);

Parameters

fileName
String

The file name to load and use as source.

Returns

The object graph that is returned.

Exceptions

fileName input is null.

Remarks

Different signatures for the Load method specify different types of input for the source XAML. The Load internal implementation first creates an XmlReader by calling Create(String) and then creates a new instance of a specialized XamlReader that processes the input.

In order for the Load(String) call to successfully create an object graph, the following must be true:

  • The source is well-formed and valid XML.

  • The source is valid XAML at the language level.

  • The XAML types that are specified in the source XAML must resolve to backing types in the relevant XAML namespaces. For example, XAML types for WPF namespaces can resolve to a WPF XAML namespace as specified in the XAML; the assemblies for WPF must be included in the project or be available in the run time; and so on.

Applies to

.NET Framework 4.8.1 och andra versioner
Produkt Versioner
.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(XamlReader)

Loads a specific XAML reader implementation and returns an object graph.

C#
public static object Load(System.Xaml.XamlReader xamlReader);

Parameters

xamlReader
XamlReader

The XAML reader implementation to use as the reader for this Load operation.

Returns

The object graph that is returned.

Exceptions

xamlReader input is null.

Remarks

You should typically use this signature only in the following cases:

  • You defined your own implementation of a XamlReader.

  • You specified settings for a XamlReader that differ from the default settings.

Applies to

.NET Framework 4.8.1 och andra versioner
Produkt Versioner
.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)

Loads a specific XML reader implementation and returns an object graph.

C#
public static object Load(System.Xml.XmlReader xmlReader);

Parameters

xmlReader
XmlReader

The XmlReader implementation to use as the reader for this Load operation.

Returns

The output object graph.

Exceptions

xamlReader input is null.

Remarks

You should typically use this signature only if you defined your own implementation of a XmlReader.

Applies to

.NET Framework 4.8.1 och andra versioner
Produkt Versioner
.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