How do I create DataTemplate in win8 (WinRT) App using code behind file i.e. using C# instead of xaml.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I can see why this might be useful if you want to create the template depending on what kind of thing you’re displaying.
The key to making this work is Windows.UI.Xaml.Markup.XamlReader.Load(). It takes a string containing your data template and parses it into a DataTemplate object. THen you can assign that object to wherever you want to use it. In the example below, I assign it to the ItemTemplate field of a ListView.
Here is some XAML:
And here is the code-behind that creates the DataTemplate: