2017-08-08 63 views
2

是否可以禁用ComboBox下拉菜單中的自動滾動效果?問題是當鼠標懸停在開放的最後一個元素ComboBox上時,它會自動滾動到下一個元素。在組合框中禁用滾動鼠標移動(WPF)

而在我的情況下,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

請添加一個例子,你的問題 – Ben

回答

1

你可以處理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; 
} 
+0

這實際上工作!謝謝您的幫助 :) – smithmartin