Click here to Skip to main content
11,715,491 members (86,036 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: XAML
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 Smile | :)
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 at 23-Apr-11 13:04pm
Comment from OP:
I need to build Xaml at runtime - my Xaml is dynamically built on runtime.
SAKryukov at 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 at 24-Apr-11 14:06pm
This is correct suggestion, my 5.
Nishant Sivakumar at 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
0 Sergey Alexandrovich Kryukov 683
1 Richard MacCutchan 280
2 Maciej Los 259
3 OriginalGriff 160
4 F-ES Sitecore 135
0 Sergey Alexandrovich Kryukov 1,003
1 Richard MacCutchan 430
2 CHill60 415
3 Maciej Los 399
4 OriginalGriff 385

Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 23 Apr 2011
Copyright © CodeProject, 1999-2015
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