|
1 | 1 | Public Class MyScrollViewer |
2 | 2 | Inherits ScrollViewer |
| 3 | + Public Sub New() |
| 4 | + [AddHandler](MouseWheelEvent, New MouseWheelEventHandler(AddressOf MouseWheelEventSub), handledEventsToo:=True) |
| 5 | + End Sub |
3 | 6 |
|
4 | 7 | Public Property DeltaMult As Double = 1 |
5 | 8 |
|
6 | 9 |
|
7 | 10 | Private RealOffset As Double |
8 | | - Private Sub MyScrollViewer_PreviewMouseWheel(sender As Object, e As MouseWheelEventArgs) Handles Me.PreviewMouseWheel |
9 | | - If e.Delta = 0 OrElse ActualHeight = 0 OrElse ScrollableHeight = 0 Then Exit Sub |
10 | | - Dim SourceType = e.Source.GetType |
11 | | - If Content.TemplatedParent Is Nothing AndAlso ( |
12 | | - (GetType(ComboBox).IsAssignableFrom(SourceType) AndAlso CType(e.Source, ComboBox).IsDropDownOpen) OrElse |
13 | | - (GetType(TextBox).IsAssignableFrom(SourceType) AndAlso CType(e.Source, TextBox).AcceptsReturn) OrElse |
14 | | - GetType(ComboBoxItem).IsAssignableFrom(SourceType) OrElse |
15 | | - TypeOf e.Source Is CheckBox) Then |
16 | | - '如果当前是在对有滚动条的下拉框或文本框执行,则不接管操作 |
17 | | - Exit Sub |
| 11 | + Protected Overrides Sub OnMouseWheel(e As MouseWheelEventArgs) |
| 12 | + 'ScrollViewer 会直接把事件移交 ScrollInfo 并 Handle 掉,在此覆盖掉它的行为 |
| 13 | + End Sub |
| 14 | + Private Sub MouseWheelEventSub(sender As Object, e As MouseWheelEventArgs) |
| 15 | + If e.Handled Then |
| 16 | + Dim ShouldProcess As Boolean = False |
| 17 | + '特判:如果事件被处理但是鼠标处在一个没有垂直滚动栏的 FlowDocumentScrollViewer 上,依然处理该事件 |
| 18 | + Dim Element = TryCast(e.Source, DependencyObject) |
| 19 | + While Element IsNot Nothing |
| 20 | + If TypeOf Element Is FlowDocumentScrollViewer Then |
| 21 | + If CType(Element, FlowDocumentScrollViewer).VerticalScrollBarVisibility = ScrollBarVisibility.Hidden Then ShouldProcess = True |
| 22 | + Exit While |
| 23 | + End If |
| 24 | + Element = If(TryCast(Element, FrameworkContentElement)?.Parent, TryCast(Element, FrameworkElement)?.Parent) |
| 25 | + End While |
| 26 | + If Not ShouldProcess Then Exit Sub |
18 | 27 | End If |
19 | 28 | e.Handled = True |
| 29 | + If e.Delta = 0 OrElse ActualHeight = 0 OrElse ScrollableHeight = 0 Then Exit Sub |
20 | 30 | PerformVerticalOffsetDelta(-e.Delta) |
21 | 31 | '关闭 Tooltip (#2552) |
22 | 32 | For Each TooltipBorder In Application.ShowingTooltips |
|
0 commit comments