From 51003c2f3e197904bee0b439b151edac49b342d0 Mon Sep 17 00:00:00 2001 From: NLNet Date: Thu, 31 Aug 2023 10:09:12 +0800 Subject: [PATCH] Fix the scrollbar attaching to wrong scrollviewer, like scrollviewer outer a datagrid. --- src/Avalonia.Controls/Primitives/ScrollBar.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/ScrollBar.cs b/src/Avalonia.Controls/Primitives/ScrollBar.cs index 86bea8daa5..264b944566 100644 --- a/src/Avalonia.Controls/Primitives/ScrollBar.cs +++ b/src/Avalonia.Controls/Primitives/ScrollBar.cs @@ -195,14 +195,15 @@ namespace Avalonia.Controls.Primitives } /// - /// Locates the first ancestor and binds to its properties. Properties which have been set through other means are not bound. + /// Try to attach to TemplatedParent if it is a and binds to its properties. + /// Properties which have been set through other means are not bound. /// /// /// This method is automatically called when the control is attached to a visual tree. /// internal void AttachToScrollViewer() { - var owner = this.FindAncestorOfType(); + var owner = this.TemplatedParent as ScrollViewer; if (owner == null) {