I know it is an work-around, but I published a tip in code project (http://www.codeproject.com/Tips/808808/Create-Data-and-Control-Templates-using-Delegates) that allows you to create a data-template using a delegate.
For example:
TemplateGenerator.CreateDataTemplate(() => new TextBox());
This will be enough to create a datatemplate that creates a new textbox. If you want a binding too, it could be written like:
TemplateGenerator.CreateDataTemplate
(
() =>
{
var result = new TextBox();
result.SetBinding(TextBox.TextProperty, "PathForTheBinding");
return result;
}
);
The code of the TemplateGenerator is the following:
///
/// Class that helps the creation of control and data templates by using delegates.
///
public static class TemplateGenerator
{
private sealed class _TemplateGeneratorControl:
ContentControl
{
internal static readonly DependencyProperty FactoryProperty = DependencyProperty.Register("Factory", typeof(Func