Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello.
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 http://blogs.msdn.com/b/scmorris/archive/2008/04/14/defining-silverlight-datagrid-columns-at-runtime.aspx[^]

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 :

XML
CellTemp.Append("<DataTemplate ");
                                CellTemp.Append("xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' >");
                                CellTemp.Append("<TextBox Text="{Binding MyProperty, Mode=TwoWay}" KeyDown="TextboxEdit_KeyDown></TextBox> ");
                                CellTemp.Append("</DataTemplate>");
and I succeed doing :
gt = new DataGridTemplateColumn();


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


Please, help.

Thanks :)
Posted

1 solution

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.
 
Share this answer
 
Comments
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.
Sergey Alexandrovich Kryukov 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.
--SA
Sergey Alexandrovich Kryukov 24-Apr-11 14:06pm    
This is correct suggestion, my 5.
--SA
Nish Nishant 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900