@@ -281,6 +281,8 @@ protected async override void OnApplyTemplate()
281281 _headerRow = GetTemplateChild ( "HeaderRow" ) as TableViewHeaderRow ;
282282 _scrollViewer = GetTemplateChild ( "ScrollViewer" ) as ScrollViewer ;
283283 _headerRowDefinition = GetTemplateChild ( "HeaderRowDefinition" ) as RowDefinition ;
284+ if ( _scrollViewer is not null ) _scrollViewer . Loaded += OnScrollViewerLoaded ;
285+
284286 if ( IsLoaded )
285287 {
286288 while ( ItemsPanelRoot is null ) await Task . Yield ( ) ;
@@ -292,9 +294,9 @@ protected async override void OnApplyTemplate()
292294 }
293295
294296 /// <summary>
295- /// Handles the Loaded event of the TableView control.
297+ /// Handles the Loaded event of the ScrollViewer control.
296298 /// </summary>
297- private void OnLoaded ( object sender , RoutedEventArgs e )
299+ private void OnScrollViewerLoaded ( object sender , RoutedEventArgs e )
298300 {
299301 var scrollPresenter = _scrollViewer ? . FindDescendant < ScrollContentPresenter > ( ) ;
300302 var xScrollBar = _scrollViewer ? . FindDescendant < ScrollBar > ( sb => sb . Name is "HorizontalScrollBar2" ) ;
@@ -316,7 +318,13 @@ private void OnLoaded(object sender, RoutedEventArgs e)
316318 Mode = BindingMode . TwoWay ,
317319 Source = this
318320 } ) ;
319-
321+ }
322+
323+ /// <summary>
324+ /// Handles the Loaded event of the TableView control.
325+ /// </summary>
326+ private void OnLoaded ( object sender , RoutedEventArgs e )
327+ {
320328 EnsureAutoColumns ( ) ;
321329 }
322330
@@ -1514,4 +1522,4 @@ internal void UpdateHorizontalScrollBarMargin()
15141522 var offset = CellsHorizontalOffset + Columns . VisibleColumns . Where ( c => c . IsFrozen ) . Sum ( c => c . ActualWidth ) ;
15151523 AttachedPropertiesHelper . SetFrozenColumnScrollBarSpace ( _scrollViewer , offset ) ;
15161524 }
1517- }
1525+ }
0 commit comments