Skip to content

Commit eca4a48

Browse files
Mitigate quick keypresses causing tab animation to stop
If an animation is in progress, we simply ignore keypresses that would otherwise cause a new tab navigation.
1 parent a4512b4 commit eca4a48

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Diagnostics;
1+
using System.Diagnostics;
22
using System.Windows.Media.Animation;
33
using Microsoft.Xaml.Behaviors;
44

@@ -41,11 +41,13 @@ private static void OnTabControlChanged(DependencyObject d, DependencyPropertyCh
4141
{
4242
oldTabControl.SelectionChanged -= behavior.OnTabChanged;
4343
oldTabControl.SizeChanged -= behavior.OnTabControlSizeChanged;
44+
oldTabControl.PreviewKeyDown -= behavior.OnTabControlPreviewKeyDown;
4445
}
4546
if (e.NewValue is TabControl newTabControl)
4647
{
4748
newTabControl.SelectionChanged += behavior.OnTabChanged;
4849
newTabControl.SizeChanged += behavior.OnTabControlSizeChanged;
50+
newTabControl.PreviewKeyDown += behavior.OnTabControlPreviewKeyDown;
4951
}
5052
}
5153

@@ -110,6 +112,15 @@ private void AddPaddingToScrollableContentIfWiderThanViewPort()
110112
}
111113
}
112114

115+
private void OnTabControlPreviewKeyDown(object sender, KeyEventArgs e)
116+
{
117+
if (!_isAnimatingScroll)
118+
return;
119+
120+
if (e.Key is Key.Left or Key.Right or Key.Home or Key.End or Key.PageUp or Key.PageDown)
121+
e.Handled = true;
122+
}
123+
113124
protected override void OnAttached()
114125
{
115126
base.OnAttached();

0 commit comments

Comments
 (0)