Skip to main content

Microsoft Silverlight

Answered Question How to Dynamically add Datatemplate in DataForms?RSS Feed

(0)

abhinayabhi
abhinayabhi

Member

Member

183 points

77 Posts

How to Dynamically add Datatemplate in DataForms?

Hi,

I want to add dynamic datatemplates in to Dataform through C# code, does any one know how to acheive this.?

 Thanks 

Abhinay.

varshavmane
varshavmane

Contributor

Contributor

6597 points

1,562 Posts

Re: How to Dynamically add Datatemplate in DataForms?

Hi,

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 ?

Please "Mark as Answer" if this post answered your question. :)
Visit my Blog: http://varshavmane.blogspot.com/

abhinayabhi
abhinayabhi

Member

Member

183 points

77 Posts

Re: How to Dynamically add Datatemplate in DataForms?

 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,

Abhinay.

lee_sl
lee_sl

Contributor

Contributor

2990 points

584 Posts

Re: Re: How to Dynamically add Datatemplate in DataForms?

could you give some more details?

----------------------------------------------
Available for consulting in Dallas, TX
http://leeontech.wordpress.com/

abhinayabhi
abhinayabhi

Member

Member

183 points

77 Posts

Re: Re: How to Dynamically add Datatemplate in DataForms?

 Hi,

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.

 Thanks,

Abhinay.


abhinayabhi
abhinayabhi

Member

Member

183 points

77 Posts

Answered Question

Re: How to Dynamically add Datatemplate in DataForms?

 Thanks for great help Smile,

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);
}
 
Thanks,
Abhinay 
  

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities