語言

XamlReader.Load 方法

定義

讀取 XAML 輸入並回傳對應物件樹的根節點。

多載

名稱 Description
Load(Stream)

讀取指定的 Stream XAML 輸入,並回傳 該 Object ,即對應物件樹的根節點。

Load(XamlReader)

透過提供的 XamlReader XAML 輸入讀取,並回傳一個物件,該物件是對應物件樹的根節點。

Load(XmlReader)

讀取指定的 XmlReader XAML 輸入,並回傳一個作為對應物件樹根的物件。

Load(Stream, Boolean)

讀取指定 Stream 物件中的 XAML 輸入,並回傳對應物件樹的根節點。

Load(Stream, ParserContext)

讀取指定的 Stream XAML 輸入,並回傳一個作為對應物件樹根的物件。

Load(XmlReader, Boolean)

讀取指定 XmlReader 物件中的 XAML 輸入,並回傳對應物件樹的根節點。

Load(Stream, ParserContext, Boolean)

透過指定的ParserContext讀取 XAML 輸入Stream,並回傳對應物件樹的根節點。

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 要以串流形式載入。

傳回

建立物件樹根節點的物件。

例外狀況

stream 是 null。

範例

以下範例是利用 類別將 a Button 儲存為 aMemoryStream。XamlWriter 接著,串流會用類別上的Button靜態Load方法載入回 aXamlReader。

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

XmlReader那個已經載入 XAML 輸入,並以 XML 格式載入。

傳回

即所建立物件樹根節點的物件。

例外狀況

reader 是 null。

範例

以下範例使用 類別Button將 a XamlWriter 轉換成字串。 接著,字串會用類別上的Button靜態Load方法載入回 aXamlReader。

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

讀取指定 Stream 物件中的 XAML 輸入,並回傳對應物件樹的根節點。

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

包含 XAML 輸入的串流。

useRestrictiveXamlReader
Boolean

true限制潛在危險類型的實例化;否則,。 false

傳回

建立物件樹的根節點。

例外狀況

stream 是 null。

備註

限制模式是一種縱深防禦措施。 不要把一個受限制的不受信任 XAML 解析視為安全,或是低權限沙盒中隔離的替代品。

適用於

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

解析器所使用的上下文資訊。

傳回

即所建立物件樹根節點的物件。

例外狀況

stream 是 null。

-或-

parserContext 是 null。

另請參閱

適用於

Load(XmlReader, Boolean)

讀取指定 XmlReader 物件中的 XAML 輸入,並回傳對應物件樹的根節點。

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

一個包含 XAML 輸入的現有 XmlReader 裝置。

useRestrictiveXamlReader
Boolean

true限制潛在危險類型的實例化;否則,。 false

傳回

建立物件樹的根節點。

例外狀況

reader 是 null。

備註

限制模式是一種縱深防禦措施。 不要把一個受限制的不受信任 XAML 解析視為安全,或是低權限沙盒中隔離的替代品。

適用於

Load(Stream, ParserContext, Boolean)

透過指定的ParserContext讀取 XAML 輸入Stream,並回傳對應物件樹的根節點。

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

包含 XAML 輸入的串流。

parserContext
ParserContext

解析器所使用的上下文資訊。

useRestrictiveXamlReader
Boolean

true限制潛在危險類型的實例化;否則,。 false

傳回

建立物件樹的根節點。

例外狀況

stream 是 null。

備註

限制模式是一種縱深防禦措施。 不要把一個受限制的不受信任 XAML 解析視為安全,或是低權限沙盒中隔離的替代品。

適用於