Skip to content

Commit a4512b4

Browse files
Implement "destructive read" of TabScrollDirection
This a safety guard to avoid leaving an invalid value which may incorrectly "overscroll" when it should not.
1 parent 0200ded commit a4512b4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/MaterialDesignThemes.Wpf/Internal/PaddedBringIntoViewStackPanel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+

22
using MaterialDesignThemes.Wpf.Behaviors.Internal;
33

44
namespace MaterialDesignThemes.Wpf.Internal;
@@ -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 PropertyMetadata(TabScrollDirection.Unknown));
16+
typeof(PaddedBringIntoViewStackPanel), new FrameworkPropertyMetadata(TabScrollDirection.Unknown, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
1717

1818
public double HeaderPadding
1919
{
@@ -49,13 +49,13 @@ private static void OnRequestBringIntoView(object sender, RoutedEventArgs e)
4949
{
5050
e.Handled = true;
5151

52-
// TODO: Consider making the "ScrollDirection" a destructive read (i.e. reset the value once it is read) to avoid leaving a Backward/Forward value that may be misinterpreted at a later stage.
5352
double offset = panel.ScrollDirection switch
5453
{
5554
TabScrollDirection.Backward => -panel.HeaderPadding,
5655
TabScrollDirection.Forward => panel.HeaderPadding,
5756
_ => 0
5857
};
58+
panel.ScrollDirection = TabScrollDirection.Unknown; // Destructive read of panel.ScrollDirection to avoid leaving an invalid value in the DP (and AP).
5959
var point = child.TranslatePoint(new Point(), panel);
6060
var newTargetRect = new Rect(new Point(point.X + offset, point.Y), child.RenderSize);
6161
panel.BringIntoView(newTargetRect);

0 commit comments

Comments
 (0)