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?
Asked
Active
Viewed 908 times
1
-
1What have you already tried? – Makyen Jan 08 '15 at 08:51
-
I have tried to Override OnMouseDown. I dont't have other idea. – Dawid Jablonski Jan 08 '15 at 09:02
1 Answers
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