繁体   English   中英

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

[英]Disable scrolling for mouse-over in ComboBox (WPF)

是否可以在“ 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

谢谢你的帮助!

您可以为ComboBoxItem容器处理RequestBringIntoView事件:

<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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM