Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems that the <code>Toolbar</code> control affects the <code>ComboBox</code> control in some way. And strangely, the <code>ComboBox</code> isn't closed when you put the cursor inside the <code>TextBox</code>, but works wrong with the <code>CheckBox</code>.</p> <p>The quickest way to solve this issue is to change focus manually when a user clicks the <code>CheckBox</code>. I use the following sequence of steps:</p> <p>1) Handle the <code>GotFocus</code> event for every control in the application</p> <p>2) Leave only events of the <code>CheckBox</code> control</p> <p>3) Check whether the <code>CheckBox</code> is inside the current <code>ComboBox</code></p> <p>4) If yes, return focus to the <code>ComboBox</code></p> <pre><code> public MainWindow() { InitializeComponent(); //... comboBox.AddHandler(FrameworkElement.GotFocusEvent, (RoutedEventHandler)OnGotFocus); } private void OnGotFocus(object sender, RoutedEventArgs e) { if (e.OriginalSource is CheckBox) { var comboBox = (ComboBox)sender; var comboBoxItem = GetParentElement&lt;ComboBoxItem&gt;(e.OriginalSource); if (comboBoxItem != null &amp;&amp; comboBox.Items.OfType&lt;object&gt;().Select(comboBox.ItemContainerGenerator.ContainerFromItem).Contains(comboBoxItem)) comboBox.Focus(); } } private T GetParentElement&lt;T&gt;(object element) where T : DependencyObject { var current = element as DependencyObject; while (current != null &amp;&amp; !(current is T)) { current = VisualTreeHelper.GetParent(current); } return current as T; } </code></pre> <p>It is a quite messy solution, but anyway it works.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload