Search code examples
wpfscrollcombobox

ComboBox cannot scroll when dropdown is open if the PreviewMouseWheel event is handled


I have a ComboBox in xaml.

<ComboBox
 x:Name="comboBox"
 ItemsSource="{Binding Angle.Collection}"
 Text="{Binding Angle.Option, StringFormat='{}{0}°'}" />

I do not want it to change item when cursor is over the combobox and rotate the mouse wheel. So I handle the PreviewMouseWheel event like this:

comboBox.PreviewMouseWheel += (o,e)=>{e.Handled = true;};

But I run into the problem that when the dropdown is open, I cannot scroll the items if there are many items, even though I set True to the ScrollViewer.CanContentScroll.

How can I solve it?


Solution

  • Change it to comboBox.PreviewMouseWheel += (o, e) => { if (!comboBox.IsDropDownOpen) e.Handled = true; };