Reputation: 53
Is it possible to disable the autoscrolling effect in a ComboBox
Dropdown? The Problem is when the mouse is hovered over the last element of the open ComboBox
it automatically scrolls to the next element.
And in my case the ComboBox
is at the bottom of the screen and the list is displayed upwards and when i open the ComboBox
and move the mouse, it scrolls down immediately.. My XAML looks like this:
<ComboBox x:Name="serverSelection" ScrollViewer.CanContentScroll="False" Width="268" Height="54" FontSize="18" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" SelectedIndex="0">
<ComboBoxItem Content="xenappts01" HorizontalAlignment="Left" Width="280" Height="54" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<ComboBoxItem Content="xenappts02" HorizontalAlignment="Left" Width="280" Height="54" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<ComboBoxItem Content="xenappts03" HorizontalAlignment="Left" Width="280" Height="54" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<ComboBoxItem Content="xenappts04" HorizontalAlignment="Left" Width="280" Height="54" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<ComboBoxItem Content="xenappts05" HorizontalAlignment="Left" Width="280" Height="54" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<ComboBoxItem Content="xenappts05c" HorizontalAlignment="Left" Width="280" Height="54" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
</ComboBox>
I tried to set ScrollViewer.CanContentScroll="False"
but that didnt work.
This is what it looks like:
https://i.sstatic.net/GcwJX.gif
Thanks for your help!
Upvotes: 5
Views: 3476
Reputation: 169190
You could handle the RequestBringIntoView
event for the ComboBoxItem
containers:
<ComboBox>
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<EventSetter Event="RequestBringIntoView" Handler="ComboBox_RequestBringIntoView"/>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
private void ComboBox_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
e.Handled = true;
}
Upvotes: 6