This is what I do and it works:
if (condition...)
{
ComboBoxItem cbi2 = new ComboBoxItem();
cbi2.Content = new TextBox() { Background= Brushes.Red, HorizontalAlignment= HorizontalAlignment.Stretch, Margin=new Thickness(0) , Height = 5, IsHitTestVisible=false, BorderBrush=null};
ibw.cmbOptions.Items.Add(cbi2);
}
the only problem is that the textBox despite not being IsHitTestVisible is selectable and that is a problem. So I'm open also to totally different solution. The only constraint is to act from code.
I can see 2 options here:
First, simply use the Separator
element:
ibw.cmbOptions.Items.Add(new Separator());
Or, you could disable the ComboBoxItem
, which would make it non-selectable for the ComboBox
.
ComboBoxItem cbi2 = new ComboBoxItem();
cbi2.IsEnabled = false;
cbi2.Content = new TextBox() { Background= Brushes.Red, HorizontalAlignment= HorizontalAlignment.Stretch, Margin=new Thickness(0) , Height = 5, IsHitTestVisible=false, BorderBrush=null};
ibw.cmbOptions.Items.Add(cbi2);