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
。
範例
下列範例會使用 XamlWriter 類別將 儲存Button至 MemoryStream 。 接著,資料流會使用 類別上的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 一併初始化。
傳回
屬於所建立之物件樹狀結構根的物件。
例外狀況
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 使用 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
剖析器使用的內容資訊。
傳回
屬於所建立之物件樹狀結構根的物件。
例外狀況
另請參閱
適用於
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