1

Normally, when ComboBox has drop-down opened I need two mouse clicks to give focus to other control. First click will close drop-down, second will give focus to other control. I need a way to give focus to other control just by one mouse click. Any idea how to do it in WPF?

Dawid Jablonski
  • 523
  • 4
  • 15

1 Answers1

0

you can handle the DropDownClosed event of the combobox control like so:

private void comboBox_DropDownClosed(object sender, EventArgs e)
    {
        Point m = Mouse.GetPosition(this);
        VisualTreeHelper.HitTest(this, new HitTestFilterCallback(FilterCallback),
            new HitTestResultCallback(ResultCallback), new PointHitTestParameters(m));
    }
    private HitTestFilterBehavior FilterCallback(DependencyObject o)
    {
        var c = o as Control;
        if ((c != null) && !(o is MainWindow))
        {
            if (c.Focusable)
            {
                c.Focus();
                return HitTestFilterBehavior.Stop;
            }
        }
        return HitTestFilterBehavior.Continue;
    }

    private HitTestResultBehavior ResultCallback(HitTestResult r)
    {
        return HitTestResultBehavior.Continue;
    }

this is based on a solution provided here

Community
  • 1
  • 1
SamTh3D3v
  • 9,854
  • 3
  • 31
  • 47