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
23
votes
4 answers

Weird XAML parsing error when trying to set TextBox.IsReadOnly

I've managed to reduce this to a simple test case. An exception is thrown during the parsing of this XAML using XamlReader.Parse():
Cameron
  • 96,106
  • 25
  • 196
  • 225
12
votes
1 answer

Loading vector graphics from XAML files programmatically in a WPF application

I would like to load vector graphics stored as XAML files (separate files, not in a dictionary), embedded in my application, and I have a few questions to do so: XAML looks a bit ambiguous, since it can be used to represent either static resources…
thomasc
  • 935
  • 9
  • 18
9
votes
5 answers

XamlReader.Load in a Background Thread. Is it possible?

A WPF app has an operation of loading a user control from a separate file using XamlReader.Load() method: StreamReader mysr = new StreamReader(pathToFile); DependencyObject rootObject = XamlReader.Load(mysr.BaseStream) as…
rem
  • 16,745
  • 37
  • 112
  • 180
8
votes
1 answer

Bindings not applied to dynamically-loaded xaml

I'm using XamlReader successfully to load a xaml file and create a FrameworkElement to work with. The xaml I'm loading has binding expressions in it such as: If I place the FrameworkElement I…
Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220
8
votes
1 answer

Interaction triggers inside DataTemplate not working with XamlReader

I'm trying to parse with XamlReader.Load() a DataTemplate (for a WPF datagrid) created dynamically in code behind : DataTemplate dataTemplate; StringReader template = new StringReader($@"
Manu
  • 1,685
  • 11
  • 27
8
votes
1 answer

Can XamlReader load xaml that contains types defined in external assemblies?

The XamlReader is loading Xaml using types defined within the local assembly and the WPF assemblies without any problems. If I include types defined within external assemblies then a XamlParseException with the following message is thrown. Cannot…
Scott Munro
  • 13,369
  • 3
  • 74
  • 80
8
votes
1 answer

C# Attribute XmlIgnore and XamlWriter class - XmlIgnore not working

I have a class, containing a property Brush MyBrush marked as [XmlIgnore]. Nevertheless it is serialized in the stream causing trouble when trying to read via XamlReader. I did some tests, e.g. when changing the visibility of the Property (to…
Horst Walter
  • 13,663
  • 32
  • 126
  • 228
8
votes
2 answers

Insert contents from the one FlowDocument into another when using XamlReader and XamlWriter

I use FlowDocument with BlockUIContainer and InlineUIContainer elements containing (or as base classes) some custom blocks - SVG, math formulas etc. Because of that using Selection.Load(stream, DataFormats.XamlPackage) wont work as the serialization…
too
  • 3,009
  • 4
  • 37
  • 51
6
votes
2 answers

Problems with XamlReader generating DataTemplate

I'm trying to implement the code below in my WPF project in order to generate DataTemplates on the fly for a DataGrid with dynamic columns. I found the code on StackOverflow here public DataTemplate Create(Type type) { return…
Caustix
  • 569
  • 8
  • 26
5
votes
1 answer

Successfully referencing ResourceDictionary in file being loaded by XamlReader.Load()

I am building a common WP7 assembly which will display common help/about information for my apps, each app assembly will specify a pair of StackPanels which have some of the app specific information (well call em Legal.xaml and…
5
votes
2 answers

Silverlight 4.0: DataTemplate Error

Im trying to get the specific template in my resource dictionary. This is my resource dictionary
xscape
  • 3,318
  • 9
  • 45
  • 86
4
votes
1 answer

Strange XAML Parse behaviour when set Text and add Interaction.Triggers. WPF

I set the Text property of the Textbox control, and also i add an Interaction.Trigger to it. An exception is thrown When I try to parse the this XAML using XamlReader.Parse(): The xaml which i have is:
mihai
  • 2,746
  • 3
  • 35
  • 56
4
votes
1 answer

XamlReader with Images

I'm creating an application in WPF (.Net 3.5) that I want to be able to customize on a per-client basis. I abstracted out the resources to external xaml (theme) files. With the xaml file built as a Page, this works perfect. Now I want to use…
holtkampw
  • 367
  • 1
  • 13
3
votes
1 answer

XamlReader - mapping multiple CLR namespaces to single XML namespace

I have a WPF project with an AssemblyInfo.cs that groups multiple CLR namespaces into a single XML namespace: [assembly: XmlnsDefinition("http://foo.bar", "MyLibary.Controls")] [assembly: XmlnsDefinition("http://foo.bar", "MyLibary.Converters")] In…
FunnyItWorkedLastTime
  • 3,225
  • 1
  • 22
  • 20
3
votes
1 answer

XamlReader throws when loading generic.xaml to merge resource dictionaries

Trying to load generic.xaml in code but it throws a XamlParseException. Code as follows: Uri uri = new Uri("Themes/Generic.xaml", UriKind.Relative); StreamResourceInfo info = Application.GetResourceStream(uri); System.Windows.Markup.XamlReader…
Youp Bernoulli
  • 5,303
  • 5
  • 39
  • 59
1
2 3 4 5 6 7 8