Skip to content
Open
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
df185e4
PoC for hijacking RequestBringIntoView event
nicolaihenriksen Dec 9, 2025
8f02def
Improves tab header scrolling behavior
nicolaihenriksen Dec 9, 2025
0511117
Adding smooth/animated scrolling to the behavior
nicolaihenriksen Dec 9, 2025
721a25c
Ensure padding on tab headers is only applied when they overflow
nicolaihenriksen Dec 9, 2025
f631a2d
Adding UI tests without assertions to easily test behavior
nicolaihenriksen Dec 10, 2025
9cace11
Minor hack! Prevent double-click on tab (control) while animating
nicolaihenriksen Dec 10, 2025
7c0c9ee
Add TabAssist.AnimateTabScrolling to toggle tab switch animation feature
nicolaihenriksen Dec 10, 2025
c27cc43
Add TODO comment regarding destructive-read on TabScrollDirection AP
nicolaihenriksen Dec 10, 2025
d18d4d4
Add TabAssist.TabScrollOffset to give control of the offset
nicolaihenriksen Dec 10, 2025
4a960c0
Replace TabAssist.AnimateTabScrolling with TabAssist.TabScrollDuration
nicolaihenriksen Dec 10, 2025
9631e7a
Rename hijacking StackPanel
nicolaihenriksen Dec 14, 2025
f001a07
Rename TabScrollDirection
nicolaihenriksen Dec 14, 2025
737223f
Rename TabScrollOffset
nicolaihenriksen Dec 14, 2025
eb5d42d
Rename TabScrollDuration
nicolaihenriksen Dec 14, 2025
966c1e8
Remove debug output
nicolaihenriksen Dec 14, 2025
a604ccf
Add TabAssist.UseHeaderPadding to enable/disable new behavior
nicolaihenriksen Dec 14, 2025
0200ded
Change bring into view event listener to class handler
nicolaihenriksen Dec 21, 2025
a4512b4
Implement "destructive read" of TabScrollDirection
nicolaihenriksen Dec 21, 2025
eca4a48
Mitigate quick keypresses causing tab animation to stop
nicolaihenriksen Dec 21, 2025
fe5b943
Use tab animation even when tab has focusable content
nicolaihenriksen Dec 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding smooth/animated scrolling to the behavior
  • Loading branch information
nicolaihenriksen committed Dec 9, 2025
commit 05111176fc49d568be7be1c5e0d7131489e6cc9e
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
using System.Diagnostics;
using System.Windows.Media.Animation;
using Microsoft.Xaml.Behaviors;

namespace MaterialDesignThemes.Wpf.Behaviors.Internal;

public class TabControlHeaderScrollBehavior : Behavior<ScrollViewer>
{
public static readonly DependencyProperty CustomHorizontalOffsetProperty =
DependencyProperty.RegisterAttached("CustomHorizontalOffset", typeof(double),
typeof(TabControlHeaderScrollBehavior), new PropertyMetadata(0d, CustomHorizontalOffsetChanged));
public static double GetCustomHorizontalOffset(DependencyObject obj) => (double)obj.GetValue(CustomHorizontalOffsetProperty);
public static void SetCustomHorizontalOffset(DependencyObject obj, double value) => obj.SetValue(CustomHorizontalOffsetProperty, value);
private static void CustomHorizontalOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var scrollViewer = (ScrollViewer)d;
scrollViewer.ScrollToHorizontalOffset((double)e.NewValue);
}

public static readonly DependencyProperty TabScrollDirectionProperty =
DependencyProperty.RegisterAttached("TabScrollDirection", typeof(TabScrollDirection), typeof(TabControlHeaderScrollBehavior), new PropertyMetadata(TabScrollDirection.Unknown));
DependencyProperty.RegisterAttached("TabScrollDirection", typeof(TabScrollDirection),
typeof(TabControlHeaderScrollBehavior), new PropertyMetadata(TabScrollDirection.Unknown));
public static TabScrollDirection GetTabScrollDirection(DependencyObject obj) => (TabScrollDirection)obj.GetValue(TabScrollDirectionProperty);
public static void SetTabScrollDirection(DependencyObject obj, TabScrollDirection value) => obj.SetValue(TabScrollDirectionProperty, value);

Expand All @@ -33,12 +46,16 @@ private static void OnTabControlChanged(DependencyObject d, DependencyPropertyCh
}
}

private double? _desiredScrollStart;
private bool _isAnimatingScroll;

private void OnTabChanged(object sender, SelectionChangedEventArgs e)
{
TabControl tabControl = (TabControl)sender;

if (e.AddedItems.Count > 0)
{
_desiredScrollStart = AssociatedObject.ContentHorizontalOffset;
SetTabScrollDirection(tabControl, (IsMovingForward() ? TabScrollDirection.Forward : TabScrollDirection.Backward));
}

Expand Down Expand Up @@ -70,7 +87,23 @@ protected override void OnDetaching()

private void AssociatedObject_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
Debug.WriteLine($"HorizontalOffset: {e.HorizontalOffset}, ViewportWidth: {e.ViewportWidth}, ExtentWidth: {e.ExtentWidth}");
Debug.WriteLine($"ContentHorizontalOffset: {AssociatedObject.ContentHorizontalOffset}, HorizontalOffset: {e.HorizontalOffset}, HorizontalChange: {e.HorizontalChange}, ViewportWidth: {e.ViewportWidth}, ExtentWidth: {e.ExtentWidth}");
if (_isAnimatingScroll || _desiredScrollStart is not { } desiredOffsetStart) return;

double originalValue = desiredOffsetStart;
double newValue = e.HorizontalOffset;

_isAnimatingScroll = true;
AssociatedObject.ScrollToHorizontalOffset(originalValue);
Debug.WriteLine($"Initiating animated scroll from {originalValue} to {newValue}. Change is: {e.HorizontalChange}");
DoubleAnimation scrollAnimation = new(originalValue, newValue, new Duration(TimeSpan.FromMilliseconds(250)));
scrollAnimation.Completed += (_, _) =>
{
Debug.WriteLine("Animation completed");
_desiredScrollStart = null;
_isAnimatingScroll = false;
};
AssociatedObject.BeginAnimation(TabControlHeaderScrollBehavior.CustomHorizontalOffsetProperty, scrollAnimation);
}
}

Expand Down