title: How do I build a DataTemplate in c# code?
body: <p>I am trying to build a dropdown list for a winform interop, and I am creating the dropdown in code. However, I have a problem getting the data to bind based on the DataTemplate I specify.</p>
  
  <p>What am I missing?</p>
  
  <pre><code>drpCreditCardNumberWpf = new ComboBox();  
  DataTemplate cardLayout = new DataTemplate {DataType = typeof (CreditCardPayment)};   
  StackPanel sp = new StackPanel
  {
      Orientation = System.Windows.Controls.Orientation.Vertical
  };   
  
  TextBlock cardHolder = new TextBlock {ToolTip = "Card Holder Name"};
  cardHolder.SetBinding(TextBlock.TextProperty, "BillToName");
  sp.Children.Add(cardHolder);
  
  TextBlock cardNumber = new TextBlock {ToolTip = "Credit Card Number"};
  cardNumber.SetBinding(TextBlock.TextProperty, "SafeNumber");
  sp.Children.Add(cardNumber);
  
  TextBlock notes = new TextBlock {ToolTip = "Notes"};
  notes.SetBinding(TextBlock.TextProperty, "Notes");
  sp.Children.Add(notes);
  
  cardLayout.Resources.Add(sp, null);
  
  drpCreditCardNumberWpf.ItemTemplate = cardLayout;
  </code></pre>