是否可以在ComboBox
下拉列表中禁用自动滚动效果?问题是当鼠标悬停在打开的ComboBox
的最后一个元素上时,它会自动滚动到下一个元素。
在我的情况下,ComboBox
位于屏幕的底部,列表向上显示,当我打开ComboBox
并移动鼠标时,它立即向下滚动..我的XAML看起来像这样:
<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>
我尝试设置ScrollViewer.CanContentScroll="False"
,但这不起作用。
这就是它的样子:
https://i.stack.imgur.com/GcwJX.gif
感谢您的帮助!
答案 0 :(得分:3)
您可以处理RequestBringIntoView
容器的ComboBoxItem
事件:
<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;
}