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

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

参数

stream
Stream

要加载的 XAML,以流形式表示。

返回

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

例外

streamnull

示例

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

C#
// 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);

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.NET Framework 3.0, 3.5, 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

Load(XamlReader)

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

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

参数

reader
XamlReader

XamlReader 对象。 应使用输入 XAML 初始化此对象。

返回

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

例外

readernull

注解

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

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.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

Load(XmlReader)

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

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

参数

reader
XmlReader

已经以 XML 形式加载了要加载的 XAML 输入的 XmlReader

返回

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

例外

readernull

示例

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

C#
// 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);

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.NET Framework 3.0, 3.5, 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

Load(Stream, Boolean)

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

参数

stream
Stream
useRestrictiveXamlReader
Boolean

返回

适用于

Windows Desktop 9 和其他版本
产品 版本
Windows Desktop 5, 6, 7, 8, 9

Load(Stream, ParserContext)

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

C#
public static object Load (System.IO.Stream stream, System.Windows.Markup.ParserContext parserContext);

参数

stream
Stream

包含要加载的 XAML 输入的流。

parserContext
ParserContext

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

返回

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

例外

streamnull

parserContextnull

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.NET Framework 3.0, 3.5, 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

Load(XmlReader, Boolean)

C#
public static object Load (System.Xml.XmlReader reader, bool useRestrictiveXamlReader);

参数

reader
XmlReader
useRestrictiveXamlReader
Boolean

返回

适用于

Windows Desktop 9 和其他版本
产品 版本
Windows Desktop 5, 6, 7, 8, 9

Load(Stream, ParserContext, Boolean)

C#
public static object Load (System.IO.Stream stream, System.Windows.Markup.ParserContext parserContext, bool useRestrictiveXamlReader);

参数

stream
Stream
parserContext
ParserContext
useRestrictiveXamlReader
Boolean

返回

适用于

Windows Desktop 9 和其他版本
产品 版本
Windows Desktop 5, 6, 7, 8, 9