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
1 answer

How to load style using xamlreader

How can i load style from below xaml using XamlReader.Load()
Kiran Ahir
  • 63
  • 1
  • 7
1
vote
1 answer

Creating a HierarchicalDataTemplate in Silverlight with code

I'm trying to create a HierarchicalDataTemplate (from the Silverlight Toolkit) in code in Silverlight following this advice on creating DataTemplates from code: Creating a Silverlight DataTemplate in code However, I haven't been able to get it to…
1
vote
2 answers

WPF Update Control In Place Using XAMLReader

I have an existing item which is a child of a canvas. The item's style is contained in a resource dictionary that contains the various brushes that can be used to color the item. When an instance of the item is created it is given the default…
amarcy
  • 1,485
  • 2
  • 19
  • 28
1
vote
0 answers

Loading Xaml via XamlReader only for Preview

just got some Problems with Loading Xaml Files by Runtime. For your Information my Code-Snippet to Load the File as Content of a Usercontrol: public UserControl LoadXaml(FileInfo paramFile) { FileInfo _XamlFile = paramFile; …
Daniel
  • 95
  • 2
  • 9
1
vote
0 answers

no video but audio using wpf mediaelement

I have a richtextbox in my wpf application and I am adding videos to it by using mediaelement. Then I convert flowdocument to xaml and store it to database. When I fetch xaml from database and convert it back to flowdocument and click play button,…
1
vote
2 answers

Why would adding an assembly in a XAML file give an error?

I've got an application that reads in XAML files dynamically like this: StreamReader sr = new StreamReader(pathAndFileName); this.Content = XamlReader.Load(sr.BaseStream); In one of those XAML files that gets loaded in (they all have had their code…
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
1
vote
1 answer

Why i can't catch this Exception?

Why I can't catch the following XamlParseException? After I click the Continue button the program continues with a normal behavior (an Exception is catched and the ex.Message is printed on the console). The problem is the Visual Studio exception…
Nick
  • 10,309
  • 21
  • 97
  • 201
1
vote
0 answers

Silverlight LoadComponent from string

Welcome all Basically, in Silverlight 4 or 5, I would like to call Application.LoadComponent() for a given valid xaml content. The problem is, that this xaml is dynamically created, and is not present in resource available for URI. Normally, this…
infografnet
  • 3,749
  • 1
  • 35
  • 35
1
vote
1 answer

Restoring Bindings after XamlReader parsing

my problem is the following: In my program I let the user place shapes (class DrawingShape) on a Canvas. The Drawing Shape encapsulates a stacked path and label:
Chris
  • 3,192
  • 4
  • 30
  • 43
1
vote
1 answer

I can't use Window.Show despite of creating new Window instance

here's the problem: In my WPF application I used to load/parse my .xaml files using XamlReader.Load Method to open a window in my application. Codefragment of my function which return the window: Dim win As New Window() Dim myObject As Object Dim…
PeteH
  • 13
  • 3
1
vote
0 answers

TypeConverter is not called for property value when the value is written as a XAML element

Suppose that I have a property MyProperty of type MyType in a class MyClass. I want to use XAML to assign it some complex value of another type (let's take String, for example). So, I create MyTypeConverter which can convert from String to MyType…
Ark-kun
  • 6,358
  • 2
  • 34
  • 70
0
votes
1 answer

Load Element from XAML

I have a custom XAML User Control like this:
0
votes
1 answer

DataGridTemplateColumn with ComboBox and TextBlock

I am creating a DataGridTemplateColumn dynamically in my application. The reason for this, is because I have a TabControl and when the user wants to add a new Tab, a Datagrid is created in the TabItem. Here is the code that I have so far to create…
Eric R.
  • 1,105
  • 3
  • 21
  • 48
0
votes
2 answers

Give a name and declare event handler of a button Created at run time with C# XamlReader

I am working on a project in C# and WPF that dynamically creates a grid layout that has some text, an image, and a button. I create many of these grids, and add them to a stack panel. I create this grid using the XamlReader.Create() function. Here…
Ben313
  • 1,662
  • 3
  • 20
  • 32
0
votes
0 answers

WPF - XamlParseException using Xaml.Parse on Xaml file with custom user control type reference

I am parsing an external Xaml file at runtime using Xaml.Parse, but I am getting the following exception: System.Windows.Markup.XamlParseException failed to create TargetType from local:DemoElement. This is the external Xaml file…
Andrea
  • 125
  • 1
  • 1
  • 7