XamlReader.Load 方法

定义

读取 XAML 输入,并返回相应对象树的根。

重载

Load(Stream)

读取指定 Stream 中的 XAML 输入,并返回作为相应对象树根的 Object

Load(XamlReader)

通过所提供的 XamlReader 读取 XAML 输入,并返回作为相应对象树根的对象。

Load(XmlReader)

读取指定 XmlReader 中的 XAML 输入,并返回作为相应对象树根的对象。

Load(Stream, Boolean)
Load(Stream, ParserContext)

读取指定 Stream 中的 XAML 输入,并返回作为相应对象树根的对象。

Load(XmlReader, Boolean)
Load(Stream, ParserContext, Boolean)

Load(Stream)

读取指定 Stream 中的 XAML 输入,并返回作为相应对象树根的 Object

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,以流形式表示。

返回

所创建的对象树根处的对象。

例外

streamnull

示例

以下示例使用 XamlWriter 类将 保存到 ButtonMemoryStream 然后,使用 类上的XamlReader静态Load方法将流加载回 Button

// 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 输入,并返回作为相应对象树根的对象。

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 对象。 应使用输入 XAML 初始化此对象。

返回

已创建的对象树的根对象。

例外

readernull

注解

输入 XamlReader 可以是 Baml2006Reader。 这是在运行时加载 BAML 或用于本地化工具的方式。

适用于

Load(XmlReader)

读取指定 XmlReader 中的 XAML 输入,并返回作为相应对象树根的对象。

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 输入的 XmlReader

返回

已创建的对象树的根对象。

例外

readernull

示例

以下示例使用 XamlWriter 类将 转换为Button字符串。 然后,在 类上使用XamlReader静态Load方法将字符串加载回 Button

// 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

返回

适用于

Load(Stream, ParserContext)

读取指定 Stream 中的 XAML 输入,并返回作为相应对象树根的对象。

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 输入的流。

parserContext
ParserContext

由分析器使用的上下文信息。

返回

已创建的对象树的根对象。

例外

streamnull

parserContextnull

另请参阅

适用于

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

返回

适用于

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

返回

适用于