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, 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(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

参数

stream
Stream

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

返回

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

异常

streamnullstream is null.

示例

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

通过所提供的 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.

返回

已创建的对象树的根对象。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.

返回

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

异常

readernullreader is null.

示例

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

读取指定 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

参数

stream
Stream

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

parserContext
ParserContext

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

返回

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

异常

streamnullstream is null.

-or- parserContextnullparserContext is null.

另请参阅

适用于