// Get the template from the control
YourControlType ctl = new YourControlType();
ctl.UpdateDefaultStyle();
ControlTemplate template = ctl.Template;
// We want our xaml of be properly indented, ohterwise
// we would not be able to indent them.
XmlWriterSettings xmlSettings = new XmlWriterSettings();
xmlSettings.Indent = true;
// Make the string builder
StringBuilder sb = new StringBuilder();
XmlWriter writer = XmlWriter.Create(sb, xmlSettings);
XamlWriter.Save(template, writer);
// Now the sb.ToString() should give us the template