Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit How to Dynamically add Datatemplate in DataForms?
5 replies. Latest Post by abhinayabhi on July 30, 2009.
(0)
abhinayabhi
Member
183 points
77 Posts
07-29-2009 1:26 AM |
Hi,
I want to add dynamic datatemplates in to Dataform through C# code, does any one know how to acheive this.?
Thanks
Abhinay.
varshavmane
Contributor
6597 points
1,562 Posts
07-29-2009 2:00 AM |
Did you check this : http://tozon.info/blog/post/2009/03/15/Dynamic-Data-Forms-for-Silverlight-with-a-Data-Template-Selector-Control.aspx OR
http://tozon.info/blog/post/2009/04/07/Dynamic-Data-Forms-for-Silverlight-revisited.aspx ?
07-29-2009 4:39 AM |
Hi Varsha,
Actually I want to add some dynamic data fields to DataForm from C# code and the given link suggesting that need to add from XAML file Can you please suggest me a way to do this.
Thanks,
lee_sl
2990 points
584 Posts
07-29-2009 4:46 AM |
could you give some more details?
07-29-2009 6:16 AM |
I am creating dynamic class file (Entity) which will be going to assign to Dataform which is act as dynamic data so for that data (class file) I need to add user defined controls for each field instead of autogenerated controls to it...
For that I need to Apply dataTemplate to DataForm programmitically.
07-30-2009 5:36 AM |
Thanks for great help ,
I found the solution for my problem.
I for that I used following code..
df.EditTemplate = CreteDataTemplate(); df.OnApplyTemplate();private DataTemplate CreteDataTemplate() { string dtxaml = "<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:dataform='clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit' xmlns:controls='clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls'>" +"<StackPanel>" + "<dataform:DataField>" +"<TextBox Text='{Binding Name, Mode=TwoWay}' />" + "</dataform:DataField>" + "<dataform:DataField>" +"<TextBox Text='{Binding State, Mode=TwoWay}' />" + "</dataform:DataField>" + "<dataform:DataField>" +"<TextBox Text='{Binding Country, Mode=TwoWay}' />" + "</dataform:DataField>" + "<dataform:DataField>" + "<CheckBox IsChecked='{Binding IsMetropolitanCity, Mode=TwoWay}' />" + "</dataform:DataField>" + "<dataform:DataField>" + "<ComboBox x:Name='cboSelectedUnit' ItemsSource='{Binding Sex, Mode=TwoWay}'>" +"</ComboBox>" + "</dataform:DataField>" + "<dataform:DataField Label='Calendar'>" + "<controls:Calendar></controls:Calendar>" + "</dataform:DataField>" +"</StackPanel>" +"</DataTemplate>"; return (DataTemplate)XamlReader.Load(dtxaml); }
Abhinay