Updated: February 2009
Provides the means to parse XAML markup into an object or a tree of objects.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml
is technically instantiatable as an object in XAML because it has a default constructor. However, you generally do not do this because the only useful members of the type are methods, and the type itself has no UI purpose.
Objects that are created by generally then should be added to the existing object tree. Otherwise the object is considered disconnected, which means that it does not render, and cannot be accessed using any of the object tree techniques as applied to the main tree (FindName, LogicalTreeHelper, VisualTreeHelper). For more information on object tree concepts, see Trees in WPF.
supports the following primary scenarios:
Cloning/object factory: Without additional mechanisms, a reference type generally cannot be included in more than one position in a WPF object tree. (Examples of additional mechanisms that offer support for sharing or re-use include objects that are based on Freezable, or a shareable object type that is referenced as an item from a ResourceDictionary.) One way to clone an object that is already in the tree is to serialize the object using XamlWriter.Save, then use the serialized string as input for a call to Load, using a stream or XmlReader as intermediary.
Constructing objects based on just-in-time information: There are often other ways to have late-binding or user-supplied input change the state of existing objects. For example you could use simple property sets, or data binding. But if you have a scenario where even the type of object to create is only determinable at run-time or real-time with user interaction, then creating such an object by building up a string for Load input is often a useful technique.
Using existing resource techniques: The Stream type is used frequently in other frameworks or technologies for transferring data or objects. You can then use these pathways to store or obtain the data in XAML form that you eventually use to create an object as part of your application.
Fixed documents: Your application might load local or downloaded XPS documents for inclusion in a WPF application object tree and UI.
// 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);
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.