XamlReader.Load 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
读取 XAML 输入并返回相应对象树的根。
重载
| 名称 | 说明 |
|---|---|
| Load(Stream) | |
| 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)
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,采用流形式。
返回
创建的对象树的根目录中的对象。
例外
stream 是 null。
示例
以下示例将 a Button 保存到使用 MemoryStream 类中 XamlWriter 。 然后,将流加载回Button类上的静态Load方法。XamlReader
// 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 进行初始化。
返回
是所创建对象树根的对象。
例外
reader 是 null。
注解
输入 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 是 null。
示例
以下示例使用Button类将 a XamlWriter 转换为字符串。 然后,该字符串将加载回Button类上使用Load静态XamlReader方法。
// 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
分析器使用的上下文信息。
返回
是所创建对象树根的对象。
例外
另请参阅
适用于
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