I'm stuck in this problem. I have a combobox in my application (created in code, not XAML); I have populated it with checkboxes, because I needed a drop-down control with checkboxes inside.
Now, I don't need the combobox selection, because it's meaningless. So I wanted to show, in the text part of the control, a label.
Is there a way to do this? Here is a minimal example:
myComboBox = new System.Windows.Controls.ComboBox();
foreach (var key in myDictionary.Keys)
{
System.Windows.Controls.CheckBox chk = new System.Windows.Controls.CheckBox();
chk.Content = key;
chk.SetBinding(System.Windows.Controls.CheckBox.IsCheckedProperty, new Binding() { Mode = BindingMode.TwoWay, Source = this, Path = new PropertyPath("myDictionary[" + key + "]") });
RoutedEventHandler ev = (sender, e) =>
{
// Do something when a checkbox is changed
};
chk.Checked += ev;
chk.Unchecked += ev;
myComboBox.Items.Add(chk);
}
This way if the user clicks on a checkbox the checkbox content is displayed in the text field.
I modified it adding also
myComboBox.SelectionChanged += (sender, jender) =>
{
myComboBox.SelectedItem = null;
};
This way no text is ever displayed. But.. What if I wanted to write a fixed string inside the text part of the combobox?
Thank you