Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: XAML
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 :
 
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 :
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 5:13am

1 solution

Rate this: bad
good
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.
  Permalink  
Comments
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.
--SA
SAKryukov at 24-Apr-11 14:06pm
   
This is correct suggestion, my 5.
--SA
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 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 105
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 23 Apr 2011
Copyright © CodeProject, 1999-2014
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