While developing a simple Windows Form UI applications, I am trying to create an effect to show and close dropdown on mouse events.
Like I can open the dropdown on MouseMove
event by setting comboBox.DroppedDown = true;
However, this same is not working when I set comboBox.DroppedDown = false;
on MouseLeave
event to close it.
No idea what exactly is needs to be done here.
The problem is on MouseLeave
the dropdown does not lose focus and hence unless you select one item from list, it does not close. It waits for user to select an item from list.
If it can lose focus on MouseLeave
, would work.
Any suggestions please.
First of all I must say that I am not an experienced programmer and I just started with WPF. I know this question is two years old but I had the same issue and I found I can close the drop down list of the ComboBox using the event IsMouseDirectlyOverChanged. What was really annoying for me was that I had a ComboBox and a button, and If the drop down menu was opened without making a selection and I wanted to click the button, nothing happens at the first click because at the first click the drop down menu was closing. After this I could click on the button.
For me it's working fine: the drop down list close if I move the mouse in any direction (up, left, down, right) and a message is append to a textbox control. I don't know if this event is something new or it could be used 2 years ago too.
private void comPortList_IsMouseDirectlyOverChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (comPortList.IsDropDownOpen==true)
{
txtMsgBox.AppendText("MouseDirectlyOverChanged\n");
txtMsgBox.ScrollToEnd();
comPortList.IsDropDownOpen = false;
}
}
This event triggers when your mouse pointer is over the opened ComboBox. If you don't open the drop down list, it will not trigger.
Another thing that I've seen is that this event triggers when you enter over the opened ComboBox and also when you leave it. If I append the text before checking if the IsDropDownOpen property is true, the text "MouseDirectlyOverChanged" will appear twice in my textbox when I the mouse pointer leaves the oppened ComboBox.
If i comment the line:
comPortList.IsDropDownOpen = false;
and leave the AppendText and ScrollToEnd before if, the text will append only once.
I hope this helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With