Customized ComboBox item from Code Behind

To add a template for a combobox in the Code Behind, We can use something like this
ComboBox _newCombo = new ComboBox();
_newCombo.Name = "MyNewCombo";
StackPanel _spHorizontal;
for (int k = 0; k < 4; k++)
{
_spHorizontal = new StackPanel();
_spHorizontal.Orientation = Orientation.Horizontal;
TextBlock _newTextBlock = new TextBlock();
_newTextBlock.Text = "Text " + k.ToString();

_spHorizontal.Children.Add(_newTextBlock);

CheckBox _newCheckBox = new CheckBox();
_newCheckBox.IsChecked = true;
_newCheckBox.Name = "Check " + k.ToString();
_spHorizontal.Children.Add(_newCheckBox);
_newCombo.Items.Add(_spHorizontal);
}

_newCombo.Items.Add(_spHorizontal);

Comments