Questions tagged [xamlreader]

XamlReader Class reads XAML input and creates an object graph, using the WPF default XAML reader and an associated XAML object writer.

XamlReader supports the following primary scenarios:

  1. 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 in WPF include objects that are based on Freezable, or support for commonly shareable objects such as Brush that are referenced as an item from a ResourceDictionary.) One way to clone an object that is already in the object tree is to serialize the object using XamlWriter.Save. You then use the serialized string as input for a call to Load, with a stream or XmlReader as an intermediary.

  2. 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 the same value to set more than one property, or use data binding. But if you have a scenario where even the type of object to create is only determinable at run time or with user interaction, then creating such an object by building up a string for Load input is often a useful technique.

  3. Using existing resource techniques: The Stream type is used frequently in other frameworks or technologies for transferring data or objects across application boundaries or for similar situations. You can then use the Stream techniques to store or obtain XAML-formatted data that you eventually use to create an object as part of your application.

  4. Fixed documents: Your application might load local or downloaded XPS documents for inclusion in a WPF application object tree and UI.

Read more

108 questions
3
votes
1 answer

C# Create module catalog from XAML file

I have a problem with loading modules from a xaml file in the context of the prism library. The xaml for the modules look like this:
Juergen
  • 3,489
  • 6
  • 35
  • 59
3
votes
0 answers

How can I monitor the progress of a XamlWriter.Save() operation?

I have a FlowDocument I want to save, and later load. I think I can do this with XamlWriter.Save() and XamlReader.Load(). It works, but it takes a long time. The time it takes is the time it takes, I guess, but to make the UI more simpatico, I'd…
Cheeso
  • 189,189
  • 101
  • 473
  • 713
3
votes
0 answers

C# objects Xaml factory method for XamlWriter

My class uses an image as Property (public Image myImage). When this class is serialized (XamlWriter) it works fine, reading it back gives an exception: 'No matching constructor found on type 'System.Drawing.Bitmap'. You can use the Arguments…
Horst Walter
  • 13,663
  • 32
  • 126
  • 228
3
votes
2 answers

Using Events/Commands with XamlReader

I am dynamically building my datatemplate using XamlReader.Parse(string). The problem I have is that I can't put any events on any of the controls I create using the XamlReader. After doing some research online I've learned that this is a known…
Jen Doran
  • 31
  • 1
  • 2
3
votes
1 answer

Why does XamlReader throw when I use a ParserContext?

This works: XamlReader.Parse(""); This throws The tag 'Pig' does not exist in XML namespace 'clr-namespace:Farm;assembly=Farm': var context = new ParserContext(); context.XmlnsDictionary.Add("",…
CannibalSmith
  • 4,742
  • 10
  • 44
  • 52
3
votes
1 answer

How to control prefixes of namespaces in XML document generated by XmlWriter - generated XAML with x:Type markup extension

I am trying to generate XAML from XElements.