在 ComboBox (WPF) 中禁用鼠标悬停滚动

smi*_*tin 4 c# wpf visual-studio-2017

是否可以在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>
Run Code Online (Sandbox Code Playgroud)

我试图设置,ScrollViewer.CanContentScroll="False"但没有奏效。

这是它的样子:

https://i.stack.imgur.com/GcwJX.gif

谢谢你的帮助!

mm8*_*mm8 5

您可以处理容器的RequestBringIntoView事件ComboBoxItem

<ComboBox>
    <ComboBox.ItemContainerStyle>
        <Style TargetType="ComboBoxItem">
            <EventSetter Event="RequestBringIntoView" Handler="ComboBox_RequestBringIntoView"/>
        </Style>
    </ComboBox.ItemContainerStyle>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
private void ComboBox_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
    e.Handled = true;
}
Run Code Online (Sandbox Code Playgroud)