|
8 | 8 |
|
9 | 9 | using Avalonia; |
10 | 10 | using Avalonia.Controls; |
| 11 | +using Avalonia.Controls.Primitives; |
11 | 12 | using Avalonia.Data; |
12 | 13 | using Avalonia.Input; |
13 | 14 | using Avalonia.Interactivity; |
@@ -1010,16 +1011,23 @@ public class CombinedTextDiffPresenter : ThemedTextDiffPresenter |
1010 | 1011 | TextArea.LeftMargins.Add(new LineModifyTypeMargin()); |
1011 | 1012 | } |
1012 | 1013 |
|
| 1014 | + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) |
| 1015 | + { |
| 1016 | + base.OnApplyTemplate(e); |
| 1017 | + |
| 1018 | + _scrollViewer = e.NameScope.Find<ScrollViewer>("PART_ScrollViewer"); |
| 1019 | + if (_scrollViewer != null) |
| 1020 | + _scrollViewer.Bind(ScrollViewer.OffsetProperty, new Binding("ScrollOffset", BindingMode.TwoWay)); |
| 1021 | + } |
| 1022 | + |
1013 | 1023 | protected override void OnLoaded(RoutedEventArgs e) |
1014 | 1024 | { |
1015 | 1025 | base.OnLoaded(e); |
1016 | 1026 |
|
1017 | | - _scrollViewer = this.FindDescendantOfType<ScrollViewer>(); |
| 1027 | + ApplyTemplate(); |
| 1028 | + |
1018 | 1029 | if (_scrollViewer != null) |
1019 | | - { |
1020 | | - _scrollViewer.Bind(ScrollViewer.OffsetProperty, new Binding("ScrollOffset", BindingMode.TwoWay)); |
1021 | 1030 | _scrollViewer.ScrollChanged += OnTextViewScrollChanged; |
1022 | | - } |
1023 | 1031 | } |
1024 | 1032 |
|
1025 | 1033 | protected override void OnUnloaded(RoutedEventArgs e) |
@@ -1195,25 +1203,29 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang |
1195 | 1203 | } |
1196 | 1204 | } |
1197 | 1205 |
|
| 1206 | + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) |
| 1207 | + { |
| 1208 | + base.OnApplyTemplate(e); |
| 1209 | + |
| 1210 | + _scrollViewer = e.NameScope.Find<ScrollViewer>("PART_ScrollViewer"); |
| 1211 | + if (_scrollViewer != null) |
| 1212 | + _scrollViewer.Bind(ScrollViewer.OffsetProperty, new Binding("ScrollOffset", BindingMode.OneWay)); |
| 1213 | + } |
| 1214 | + |
1198 | 1215 | protected override void OnLoaded(RoutedEventArgs e) |
1199 | 1216 | { |
1200 | 1217 | base.OnLoaded(e); |
1201 | 1218 |
|
1202 | | - _scrollViewer = this.FindDescendantOfType<ScrollViewer>(); |
| 1219 | + ApplyTemplate(); |
| 1220 | + |
1203 | 1221 | if (_scrollViewer != null) |
1204 | | - { |
1205 | 1222 | _scrollViewer.ScrollChanged += OnTextViewScrollChanged; |
1206 | | - _scrollViewer.Bind(ScrollViewer.OffsetProperty, new Binding("ScrollOffset", BindingMode.OneWay)); |
1207 | | - } |
1208 | 1223 | } |
1209 | 1224 |
|
1210 | 1225 | protected override void OnUnloaded(RoutedEventArgs e) |
1211 | 1226 | { |
1212 | 1227 | if (_scrollViewer != null) |
1213 | | - { |
1214 | 1228 | _scrollViewer.ScrollChanged -= OnTextViewScrollChanged; |
1215 | | - _scrollViewer = null; |
1216 | | - } |
1217 | 1229 |
|
1218 | 1230 | base.OnUnloaded(e); |
1219 | 1231 | GC.Collect(); |
|
0 commit comments