Skip to content

Commit fe5b943

Browse files
Use tab animation even when tab has focusable content
Reverts the "destructive read" commit because the event may fire twice now, and removing the scroll direction would lead the second event to scroll to a wrong (i.e. not offset) position. So we live with the extra event (in cases where there is no focusable content; probably not the common use-case), and live with the AP/DP value surviving.
1 parent eca4a48 commit fe5b943

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ private void OnTabChanged(object sender, SelectionChangedEventArgs e)
7878
{
7979
_desiredScrollStart = AssociatedObject.ContentHorizontalOffset;
8080
SetScrollDirection(tabControl, (IsMovingForward() ? TabScrollDirection.Forward : TabScrollDirection.Backward));
81+
82+
// In case the TabItem has focusable content, the FrameworkElement.RequestBringIntoView won't fire. The lines below ensures that it fires.
83+
var tab = tabControl.ItemContainerGenerator.ContainerFromItem(e.AddedItems[0]) as TabItem;
84+
tab?.BringIntoView();
8185
}
8286

8387
bool IsMovingForward()

src/MaterialDesignThemes.Wpf/Internal/PaddedBringIntoViewStackPanel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public TabScrollDirection ScrollDirection
1313

1414
public static readonly DependencyProperty ScrollDirectionProperty =
1515
DependencyProperty.Register(nameof(ScrollDirection), typeof(TabScrollDirection),
16-
typeof(PaddedBringIntoViewStackPanel), new FrameworkPropertyMetadata(TabScrollDirection.Unknown, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
16+
typeof(PaddedBringIntoViewStackPanel), new PropertyMetadata(TabScrollDirection.Unknown));
1717

1818
public double HeaderPadding
1919
{
@@ -55,7 +55,6 @@ private static void OnRequestBringIntoView(object sender, RoutedEventArgs e)
5555
TabScrollDirection.Forward => panel.HeaderPadding,
5656
_ => 0
5757
};
58-
panel.ScrollDirection = TabScrollDirection.Unknown; // Destructive read of panel.ScrollDirection to avoid leaving an invalid value in the DP (and AP).
5958
var point = child.TranslatePoint(new Point(), panel);
6059
var newTargetRect = new Rect(new Point(point.X + offset, point.Y), child.RenderSize);
6160
panel.BringIntoView(newTargetRect);

0 commit comments

Comments
 (0)