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
1
vote
0 answers

ResourceDict share & set Template

I will use XAMLReader to load wpf screens. I have some ControlTemplates on Buttons.xaml file and i am keeping it in a common class library (ClassLibrary1). Buttons.xaml is like that:
makcura
  • 61
  • 2
  • 9
1
vote
0 answers

How to parse xaml file having custom class,to get the list of all objects?

I went through the tons of similar posts but nothing seems to work in my case. All I want to do is load a xaml file (located in some other assembly), and iterate through the different elements/objects to check for a certain attribute value. I could…
Deedee123
  • 11
  • 4
1
vote
2 answers

How can I keep XamlReader.Load(xamlFile) from inserting extra Run elements?

Imagine I've got a FlowDocument like so:
itsmatt
  • 31,265
  • 10
  • 100
  • 164
1
vote
2 answers

Creating a grid from string using XamlReader

I have a string representation of a XAML Grid like this:
Gal
  • 182
  • 3
  • 12
1
vote
1 answer

How can I validate an attribute value in custom XAML supplied by the user?

My app allows users to put some custom XAML markup into a textbox. When my app loads I use XamlReader.Parse to load the tree. I then overwrite some Resources in my MergedDictionaries with these custom resources. This has worked well and I can catch…
JapNolt
  • 120
  • 1
  • 9
1
vote
1 answer

WPF: Replace the XAML of a page or usercontrol (both is ok) at runtime?

I know that it is possible to parse an XAML - file at runtime and create an UIElement which I can insert into my pages grid, no problem there. But what I really want is to replace the whole XAML of my page or usercontrol, is that possible,…
1
vote
1 answer

Serialize WPF component using XamlWriter without default constructor

Ive found out that you can serialize a wpf component, in my example a FixedDocument, using the XamlWriter and a MemoryStream: FixedDocument doc = GetDocument(); MemoryStream stream = new MemoryStream(); XamlWriter.Save(doc, stream); And then to get…
Mizipzor
  • 51,151
  • 22
  • 97
  • 138
1
vote
1 answer

How do XamlReader.Read or XamlReader.Parse instantiate types in order to build the wpf tree?

I know that for controls with specified clr-namespace: and assembly= tokens, XamlReader just looks for that type in the specified assembly. But what about default WPF controls in the default namespace…
Kaitlin Hipkin
  • 189
  • 1
  • 11
1
vote
2 answers

Silverlight 3.0 Custom ListBox DataTemplate has a checkbox, checked event not firing

The datatemplate for the ListBox is set dynamically by XamlReader.Load. I am subscribing to Checked event by getting the CheckBox object using VisualTreeHelper.GetChild. This event is not getting fired Code Snippet public void SetListBox() …
1
vote
1 answer

WPF Richtextbox XamlWriter behaviour

I am trying to save some c# source code into the database. Basically I have a RichTextBox that users can type their code and save that to the database. When I copy and paste from the visual studio environment, I would like to preserve the formating…
Krishna
  • 2,451
  • 1
  • 26
  • 31
1
vote
0 answers

Controls created with XamlReader.Parse don't inherit styles

In my application the user can type in HTML, which then gets converted to XAML. I then parse the XAML using the XamlReader.Parse method and add it to a FlowDocument. For example, let's suppose I have the XAML for a paragraph stored in a string, and…
battmanz
  • 2,266
  • 4
  • 23
  • 32
1
vote
1 answer

C# WPF XAML Loading

Hi I'd like to inquire on how i can load a WPF Xaml into code so that I can change the values of the attributes of some XAML elements and output it by creating another XAML files. This is so that I can output the same file with values dynamically…
1
vote
1 answer

Button in a Grid loaded by XamlReader not responding to click

This is a project for Windows Phone 8. I have tried using a XamlReader to load a Grid containing several objects, one of which is a button. The button can be created fine, found, and attached a handler in c#, but does not seem to respond to clicks -…
1
vote
3 answers

Wpf xamlreader load xaml with custom elements

I got a canvas with custom elements, similar to texboxes and shapes. Which im saving to a file with:…
user3333128
  • 135
  • 4
  • 13
1
vote
2 answers

Error parsing StringFormat token with XamlReader

I know the below code works with VS2013/.net 4.5.1, but at work we are stuck on .net 4 and cannot upgrade to the latest.net framework (mainly because .net 4.5 is an in place replacement), appreciate if you know of a work around to the below issue. I…
Rohit Sharma
  • 6,136
  • 3
  • 28
  • 47