Creating a ControlTemplate at Run Time in Silverlight

I am writing a Silverlight application that requires me to dynamically create a ControlTemplate at runtime. Most of the solutions I found include creating a new template for each case, but I have too many things to do. How to create a new checklist in C #?

+4
source share
1 answer

You cannot create a ControlTemplate in Silverlight in C # only. Unlike WPF (where you can set the VisualTree property, there is no property you can set that indicates the "contents" of the ControlTemplate.

You can define your XAML as a string, and then dynamically load it in C #, as described in this post.

The code comes down to the following:

var template = (ControlTemplate)XamlReader.Load("<ControlTemplate " + " xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"" + " xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">" + " content here " + "</ControlTemplate>"); 
+3
source

All Articles