Skip to content

Commit 9cace11

Browse files
Minor hack! Prevent double-click on tab (control) while animating
Without this hack, if the user double-clicks on a tab that is partially out of view, it will not scroll fully into view (with the desired additional "padding"). It seems to stop the animation prematurely and leave the TabControl headers in a undesirable state. This minor hack prevents this behavior.
1 parent f631a2d commit 9cace11

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/MaterialDesignThemes.Wpf/Behaviors/Internal/TabControlHeaderScrollBehavior.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ private void AssociatedObject_ScrollChanged(object sender, ScrollChangedEventArg
138138
double newValue = e.HorizontalOffset;
139139

140140
_isAnimatingScroll = true;
141+
142+
// HACK: Temporarily disable user interaction while the animated scroll is ongoing. This prevents the double-click of a tab stopping the animation prematurely.
143+
bool originalIsHitTestVisibleValue = TabControl.IsHitTestVisible;
144+
TabControl.SetCurrentValue(FrameworkElement.IsHitTestVisibleProperty, false);
145+
141146
AssociatedObject.ScrollToHorizontalOffset(originalValue);
142147
Debug.WriteLine($"Initiating animated scroll from {originalValue} to {newValue}. Change is: {e.HorizontalChange}");
143148
DoubleAnimation scrollAnimation = new(originalValue, newValue, new Duration(TimeSpan.FromMilliseconds(250)));
@@ -146,6 +151,9 @@ private void AssociatedObject_ScrollChanged(object sender, ScrollChangedEventArg
146151
Debug.WriteLine("Animation completed");
147152
_desiredScrollStart = null;
148153
_isAnimatingScroll = false;
154+
155+
// HACK: Set the hit test visibility back to its original value
156+
TabControl.SetCurrentValue(FrameworkElement.IsHitTestVisibleProperty, originalIsHitTestVisibleValue);
149157
};
150158
AssociatedObject.BeginAnimation(TabControlHeaderScrollBehavior.CustomHorizontalOffsetProperty, scrollAnimation);
151159
}

0 commit comments

Comments
 (0)