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

XmlReader,已載入 XAML 輸入以使用 XML 格式進行載入。

傳回

屬於所建立之物件樹狀結構根的物件。

例外狀況

readernull

範例

下列範例會 Button 使用 XamlWriter 類別,將轉換成字串。 接著會使用 類別上的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

傳回

適用於