Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

How to Dynamically add Datatemplate in DataForms? RSS

6 replies

Last post Feb 17, 2010 03:00 AM by befree22

(0)
  • abhinayabhi

    abhinayabhi

    Member

    183 Points

    77 Posts

    How to Dynamically add Datatemplate in DataForms?

    Jul 29, 2009 05:26 AM | LINK

    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

    Star

    13219 Points

    2753 Posts

    Re: How to Dynamically add Datatemplate in DataForms?

    Jul 29, 2009 06:00 AM | LINK

    Please "Mark as Answer" if this post answered your question. :)
    Visit my Blog
  • abhinayabhi

    abhinayabhi

    Member

    183 Points

    77 Posts

    Re: How to Dynamically add Datatemplate in DataForms?

    Jul 29, 2009 08:39 AM | LINK

     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

    4222 Points

    864 Posts

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

    Jul 29, 2009 08:46 AM | LINK

    could you give some more details?

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

    abhinayabhi

    Member

    183 Points

    77 Posts

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

    Jul 29, 2009 10:16 AM | LINK

     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

    183 Points

    77 Posts

    Re: How to Dynamically add Datatemplate in DataForms?

    Jul 30, 2009 09:36 AM | LINK

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

    befree22

    Member

    2 Points

    1 Post

    Re: How to Dynamically add Datatemplate in DataForms?

    Feb 17, 2010 03:00 AM | LINK

    I too am interested in adding custom fields to the dataform. For instance, I'd like to exempt registered users from answering questions but have new users answer them. Also, I'd like to route clients to different webpages (ex. FAQ) based on the "reason for contact" box selected. Could someone point me in the right direction on how to add code for this?

    Data Binding control Dataform itemsource columntemplate