XamlReader::LoadAsync Method (XmlReader)

Reads the XAML input in the specified XmlReader and returns the root of the corresponding object tree.

Namespace:  System.Windows.Markup
Assembly:  PresentationFramework (in PresentationFramework.dll)

public:
Object^ LoadAsync(
	XmlReader^ reader
)

Parameters

reader
Type: System.Xml::XmlReader

An existing XmlReader that has already loaded/read the XAML input.

Return Value

Type: System::Object
The root of the created object tree.

ExceptionCondition
ArgumentNullException

reader is nullptr.

InvalidOperationException

Multiple load operations are performed concurrently with the same XamlReader.

An asynchronous XAML load operation will initially return an object that is purely the root object. Asynchronously, XAML parsing then continues, and any child objects are filled in under the root. This is in contrast to the typical WPF XAML processing behavior and its interaction with WPF concepts of object lifetime. In the typical (non-async) interaction, all properties of an object including all child collections are filled before returning an element and reporting it as loaded. That behavior equates to a bottom-up methodology for creating the tree where the root object is the last object to become available.

You typically would assign the returned object from LoadAsync to some location in your application's object tree, with the knowledge that content might still be filling in and might cause incremental layout updates if the entire content is exposed as part of the UI. For this reason it is typical to isolate or virtualize any asynchronously loaded objects from XAML, and to use application-specific logic or application state to notify when LoadCompleted is handled.

In order for LoadAsync to load XAML input asynchronously, the root element in the XAML markup must contain the attribute and value x:SynchronousMode="Async". The value is treated as case sensitive. If the XAML markup root does not contain x:SynchronousMode="Async", no exception is thrown, and the call is instead processed as a synchronous load (see Load(XmlReader)).

Only one asynchronous load operation per instance of the XamlReader class can be performed at a time. If more than one asynchronous operation is attempted on the same instance of the XamlReader class an InvalidOperationException is thrown.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft