Skip to content

Commit 7c0c9ee

Browse files
Add TabAssist.AnimateTabScrolling to toggle tab switch animation feature
Defaulted to True in a style setter allowing for easy override at the call site.
1 parent 9cace11 commit 7c0c9ee

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ protected override void OnDetaching()
132132
private void AssociatedObject_ScrollChanged(object sender, ScrollChangedEventArgs e)
133133
{
134134
Debug.WriteLine($"ContentHorizontalOffset: {AssociatedObject.ContentHorizontalOffset}, HorizontalOffset: {e.HorizontalOffset}, HorizontalChange: {e.HorizontalChange}, ViewportWidth: {e.ViewportWidth}, ExtentWidth: {e.ExtentWidth}");
135-
if (_isAnimatingScroll || _desiredScrollStart is not { } desiredOffsetStart) return;
135+
bool useAnimation = TabAssist.GetAnimateTabScrolling(TabControl);
136+
if (!useAnimation)
137+
return;
138+
if ( _isAnimatingScroll || _desiredScrollStart is not { } desiredOffsetStart)
139+
return;
136140

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

src/MaterialDesignThemes.Wpf/TabAssist.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,13 @@ public static void SetHeaderBehavior(DependencyObject obj, TabControlHeaderBehav
6969
public static readonly DependencyProperty HeaderBehaviorProperty =
7070
DependencyProperty.RegisterAttached("HeaderBehavior", typeof(TabControlHeaderBehavior), typeof(TabAssist),
7171
new PropertyMetadata(TabControlHeaderBehavior.Scrolling));
72+
73+
public static bool GetAnimateTabScrolling(DependencyObject obj)
74+
=> (bool)obj.GetValue(AnimateTabScrollingProperty);
75+
76+
public static void SetAnimateTabScrolling(DependencyObject obj, bool value)
77+
=> obj.SetValue(AnimateTabScrollingProperty, value);
78+
79+
public static readonly DependencyProperty AnimateTabScrollingProperty =
80+
DependencyProperty.RegisterAttached("AnimateTabScrolling", typeof(bool), typeof(TabAssist), new PropertyMetadata(false));
7281
}

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TabControl.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@
233233
<Setter Property="wpf:ElevationAssist.Elevation" Value="Dp4" />
234234
<Setter Property="wpf:RippleAssist.Feedback" Value="{DynamicResource MaterialDesign.Brush.Button.Ripple}" />
235235
<Setter Property="wpf:TabAssist.HasUniformTabWidth" Value="False" />
236+
<Setter Property="wpf:TabAssist.AnimateTabScrolling" Value="True" />
236237

237238
<Style.Triggers>
238239
<Trigger Property="wpf:TabAssist.HeaderBehavior" Value="Wrapping">

0 commit comments

Comments
 (0)