Click here to Skip to main content
13,053,844 members (57,877 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am looking for good example and code for building XAML on runtime (and not touch the XAML file at design time).
A sample like on[^]

I need code so I can download and learn from (not something too complicated).
... I have tried so lot to build a simple sample, and got into exception :

CellTemp.Append("<DataTemplate ");
                                CellTemp.Append("xmlns='' >");
                                CellTemp.Append("<TextBox Text="{Binding MyProperty, Mode=TwoWay}" KeyDown="TextboxEdit_KeyDown></TextBox> ");
and I succeed doing :
gt = new DataGridTemplateColumn();

The exception :
An unhandled exception ...
Code : 4004
Category : ManagedRuntimeError
Message : System.TypeInitializationException: The type initalizer for 'Missing template. Cannot Initialize.

Please, help.

Thanks :)
Posted 23-Apr-11 4:13am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

At runtime, why do you bother generating Xaml and then getting that parsed by the runtime? It makes sense when you want to load Xaml from disk, but in your case that does not seem to be the case. I would suggest that you go ahead and use procedural code to create the required UI.
Tarun.K.S 23-Apr-11 13:04pm
Comment from OP:
I need to build Xaml at runtime - my Xaml is dynamically built on runtime.
SAKryukov 24-Apr-11 14:08pm
Why it is built in runtime? Nobody will bother with answering if you do not cooperate.
What if available generation of XAML is already wrong approach? You need to explain.
SAKryukov 24-Apr-11 14:06pm
This is correct suggestion, my 5.
Nishant Sivakumar 24-Apr-11 14:07pm
Thanks SA!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 23 Apr 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100