|
1 | | - |
| 1 | + |
2 | 2 | using MaterialDesignThemes.Wpf.Behaviors.Internal; |
3 | 3 |
|
4 | 4 | namespace MaterialDesignThemes.Wpf.Internal; |
@@ -34,27 +34,31 @@ public bool UseHeaderPadding |
34 | 34 | public static readonly DependencyProperty UseHeaderPaddingProperty = |
35 | 35 | DependencyProperty.Register(nameof(UseHeaderPadding), typeof(bool), typeof(PaddedBringIntoViewStackPanel), new PropertyMetadata(false)); |
36 | 36 |
|
37 | | - public PaddedBringIntoViewStackPanel() |
38 | | - => AddHandler(FrameworkElement.RequestBringIntoViewEvent, new RoutedEventHandler(OnRequestBringIntoView), false); |
| 37 | + static PaddedBringIntoViewStackPanel() |
| 38 | + => EventManager.RegisterClassHandler(typeof(PaddedBringIntoViewStackPanel), |
| 39 | + FrameworkElement.RequestBringIntoViewEvent, |
| 40 | + new RequestBringIntoViewEventHandler(OnRequestBringIntoView)); |
39 | 41 |
|
40 | | - private void OnRequestBringIntoView(object sender, RoutedEventArgs e) |
| 42 | + private static void OnRequestBringIntoView(object sender, RoutedEventArgs e) |
41 | 43 | { |
42 | | - if (!UseHeaderPadding) |
| 44 | + var panel = (PaddedBringIntoViewStackPanel)sender; |
| 45 | + if (!panel.UseHeaderPadding) |
43 | 46 | return; |
44 | 47 |
|
45 | | - if (e.OriginalSource is FrameworkElement child && child != this) |
| 48 | + if (e.OriginalSource is FrameworkElement child && child != panel) |
46 | 49 | { |
47 | 50 | e.Handled = true; |
48 | 51 |
|
49 | 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. |
50 | | - double offset = ScrollDirection switch { |
51 | | - TabScrollDirection.Backward => -HeaderPadding, |
52 | | - TabScrollDirection.Forward => HeaderPadding, |
| 53 | + double offset = panel.ScrollDirection switch |
| 54 | + { |
| 55 | + TabScrollDirection.Backward => -panel.HeaderPadding, |
| 56 | + TabScrollDirection.Forward => panel.HeaderPadding, |
53 | 57 | _ => 0 |
54 | 58 | }; |
55 | | - var point = child.TranslatePoint(new Point(), this); |
| 59 | + var point = child.TranslatePoint(new Point(), panel); |
56 | 60 | var newTargetRect = new Rect(new Point(point.X + offset, point.Y), child.RenderSize); |
57 | | - BringIntoView(newTargetRect); |
| 61 | + panel.BringIntoView(newTargetRect); |
58 | 62 | } |
59 | 63 | } |
60 | 64 | } |
0 commit comments