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.
What am I missing?
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;
Assuming that you’ve already set up the
ItemsSourceetc fordrpCreditCardNumberWpf…You can use the same way I have set the
ToolTipon theTextBlocks to set other properties such as margins.