Creating a Silverlight DataTemplate in code
Posted
by Nick R
on Stack Overflow
See other posts from Stack Overflow
or by Nick R
Published on 2008-09-12T16:31:06Z
Indexed on
2010/05/05
3:28 UTC
Read the original article
Hit count: 873
Silverlight
How do I create a silverlight data template in code? I've seen plenty of examples for WPF, but nothing for Silverlight.
Edit: Here's the code I'm now using this for, based on the answer from Santiago below.
public DataTemplate Create(Type type)
{
return (DataTemplate)XamlReader.Load(
@"<DataTemplate
xmlns=""http://schemas.microsoft.com/client/2007"">
<" + type.Name + @" Text=""{Binding " + ShowColumn + @"}""/>
</DataTemplate>"
);
}
This works really nicely and allows me to change the binding on the fly.
© Stack Overflow or respective owner