locked
Set DataTemplate using C#

    Question

  • Hi!

    I want to modify a DataTemplate located in <Page.Resources> and all I can do is retrieving it:

    DataTemplate data= (DataTemplate)this.Resources["DataTemplate1"]; //get the resource
    var grid = (Grid)ceva.LoadContent(); //load content of it (a grid)
    grid.ColumnDefinitions[1].Width = new GridLength(150);//set the second column width to 150px

    My question is: How can I put the grid variable back in data and then in Page Resources?


    Update: My goal is to write the DataTemplate back into Page Resources (this.Resources).

    • Edited by C. Cristi Monday, April 7, 2014 8:23 PM Update
    Sunday, April 6, 2014 8:44 PM

All replies

  • What's your end goal in doing this? Do you want it to write back to the Resouces of the Page for future use, or something else?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, April 7, 2014 7:20 PM
    Moderator
  • Sorry, forgot to write the purpose. I have updated it now.

    Cris

    Monday, April 7, 2014 8:22 PM
  • So, do you want to modify the existing DataTemplate, or just create a new one? 

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, April 8, 2014 7:01 PM
    Moderator
  • Modify the existing one.

    Cris

    Tuesday, April 8, 2014 8:31 PM