XamlReader.Load 方法

定义

读取 XAML 输入,并返回相应对象树的根。Reads XAML input and returns the root of the corresponding object tree.

重载

Load(Stream)

读取指定 Stream 中的 XAML 输入,并返回作为相应对象树根的 ObjectReads the XAML input in the specified Stream and returns an Object that is the root of the corresponding object tree.

Load(XamlReader)

通过所提供的 XamlReader 读取 XAML 输入,并返回作为相应对象树根的对象。Reads the XAML input through a provided XamlReader and returns an object that is the root of the corresponding object tree.

Load(XmlReader)

读取指定 XmlReader 中的 XAML 输入,并返回作为相应对象树根的对象。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)

读取指定 Stream 中的 XAML 输入,并返回作为相应对象树根的对象。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)

读取指定 Stream 中的 XAML 输入,并返回作为相应对象树根的 ObjectReads 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

参数

stream
Stream

要加载的 XAML,以流形式表示。The XAML to load, in stream form.

返回

Object

所创建的对象树根处的对象。The object at the root of the created object tree.

例外

streamnullstream is null.

示例

下面的示例 Button 使用类将保存到 MemoryStream XamlWriterThe following example saves a Button into a MemoryStream using the XamlWriter class. 然后, Button 使用类上的静态方法将流重新加载到中 Load XamlReaderThe 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)

通过所提供的 XamlReader 读取 XAML 输入,并返回作为相应对象树根的对象。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

参数

reader
XamlReader

XamlReader 对象。A XamlReader object. 应使用输入 XAML 初始化此对象。This is expected to be initialized with input XAML.

返回

Object

已创建的对象树的根对象。The object that is the root of the created object tree.

例外

readernullreader is null.

注解

输入 XamlReader 可以为 Baml2006ReaderThe input XamlReader can be Baml2006Reader. 这是你可以在运行时加载 BAML 或用于本地化工具的方式。This is how you can load BAML at run time, or for localization tool purposes.

Load(XmlReader)

读取指定 XmlReader 中的 XAML 输入,并返回作为相应对象树根的对象。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

参数

reader
XmlReader

已经以 XML 形式加载了要加载的 XAML 输入的 XmlReaderThe XmlReader that has already loaded the XAML input to load in XML form.

返回

Object

已创建的对象树的根对象。The object that is the root of the created object tree.

例外

readernullreader is null.

示例

下面的示例使用类将转换为 Button 字符串 XamlWriterThe following example converts a Button into a string using the XamlWriter class. 然后, Button 使用类上的静态方法将该字符串重新加载到中 Load XamlReaderThe 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, 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

参数

stream
Stream
useRestrictiveXamlReader
Boolean

返回

Object

Load(Stream, ParserContext)

读取指定 Stream 中的 XAML 输入,并返回作为相应对象树根的对象。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

参数

stream
Stream

包含要加载的 XAML 输入的流。The stream that contains the XAML input to load.

parserContext
ParserContext

由分析器使用的上下文信息。Context information used by the parser.

返回

Object

已创建的对象树的根对象。The object that is the root of the created object tree.

例外

streamnullstream is null.

- 或 --or- parserContextnullparserContext is null.

另请参阅

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

参数

reader
XmlReader
useRestrictiveXamlReader
Boolean

返回

Object

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

参数

stream
Stream
parserContext
ParserContext
useRestrictiveXamlReader
Boolean

返回

Object

适用于