This thread should point you in the right direction; however, keep in mind that from a WPF stand-point it is not recommended to create DataTemplates in code. In fact, the class that is used to create them ( FrameworkElementFactory ) has been obsoleted.
Technical Writer - Xceed Software
Of all the things I've lost, I miss my mind the most. - Mark Twain