I have a simple ComboBox with CheckBoxes as Items. How can I prevent the actual selection of the items. The user should only be able to check or uncheck the checkboxes?
Ok, I already tried before to use GetBindingExpression(...).UpdateTarget() because my TextProperty is bound but nothing happend. This function will only have an effect after the layout was updated. So the result:
///
/// Prevents the selection of an item and displays the result of the TextProperty-Binding
///
///
///
private void SeveritiesComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox box = sender as ComboBox;
if (box == null)
return;
if (box.SelectedItem != null)
{
box.SelectedItem = null;
EventHandler layoutUpdated = null;
layoutUpdated = new EventHandler((o, ev) =>
{
box.GetBindingExpression(ComboBox.TextProperty).UpdateTarget();
box.LayoutUpdated -= layoutUpdated;
});
box.LayoutUpdated += layoutUpdated;
}
}