You can add XAML code as plain string in C# using a string or a string builder class. XAMLReader class is used to read, parse and render XAML code. Here is an sample code to define and set a template. Make sure to include all aliases and namespaces in XAML string.
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<DataTemplate ");
sb.Append("xmlns='http://schemas.microsoft.com/winfx/");
sb.Append("2006/xaml/presentation' ");
sb.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
sb.Append("xmlns:local = 'clr-namespace:yournamespace');
sb.Append(";assembly=<yourassembly>'>");
sb.Append("<Canvas Width='150'>");
sb.Append("<TextBlock Width='Auto' Canvas.Left='35' Canvas.Top='2' Text='{Binding Field1}' />");
sb.Append("<Image Height='20' Width='20' Canvas.Top='2' Canvas.Left='3' Source='img/details.png' ");
sb.Append("x:Name='imgDetails' />");
sb.Append("</Canvas>");
sb.Append("</DataTemplate>");
TabControl.Template = (DataTemplate)System.Windows.Markup.XamlReader.Load(sb.ToString());