1111using System . Collections . Specialized ;
1212using System . Data ;
1313using System . Linq ;
14+ using System . Threading . Tasks ;
1415using Windows . Foundation ;
1516using WinUI . TableView . Helpers ;
1617
@@ -506,39 +507,6 @@ internal void EnsureLayout()
506507 selectionIndicator = fontIcon ? . Parent as Border ;
507508 }
508509
509- if ( selectionIndicator is not null )
510- {
511- if ( IsSelected )
512- {
513- // Assign a TranslateTransform for animation
514- var translateTransform = new TranslateTransform ( ) ;
515- selectionIndicator . RenderTransform = translateTransform ;
516-
517- var toValue = Math . Round ( - detailsHeight / 2 ) ; // move up or down
518-
519- var animation = new DoubleAnimation
520- {
521- To = toValue ,
522- Duration = new Duration ( TimeSpan . Zero )
523- } ;
524-
525- var storyboard = new Storyboard ( ) ;
526- Storyboard . SetTarget ( animation , translateTransform ) ;
527- Storyboard . SetTargetProperty ( animation , "Y" ) ; // vertical movement
528- storyboard . Children . Add ( animation ) ;
529-
530- storyboard . Begin ( ) ;
531- }
532- else
533- {
534- // Row is not selected → reset any previous offset
535- if ( selectionIndicator . RenderTransform is TranslateTransform tt )
536- tt . Y = 0 ;
537- else
538- selectionIndicator . RenderTransform = null ;
539- }
540- }
541-
542510
543511 _selectionBackground ??= _itemPresenter ? . FindDescendants ( )
544512 . OfType < Border > ( )
@@ -550,6 +518,7 @@ internal void EnsureLayout()
550518 _focusVisualMargin . Right ,
551519 _focusVisualMargin . Bottom + GetHorizontalGridlineHeight ( ) ) ;
552520
521+ EnsureSelectionIndicatorPosition ( detailsHeight , selectionIndicator ) ;
553522#endif
554523 if ( _selectionBackground is not null )
555524 {
@@ -562,6 +531,36 @@ internal void EnsureLayout()
562531 }
563532 }
564533
534+ /// <summary>
535+ /// Ensures the position of the selection indicator.
536+ /// </summary>
537+ private async void EnsureSelectionIndicatorPosition ( double detailsHeight , Border ? selectionIndicator )
538+ {
539+ await Task . Yield ( ) ; // let the animations and visual state changes complete
540+
541+ if ( selectionIndicator is not null )
542+ {
543+ // Assign a TranslateTransform for animation
544+ var translateTransform = new TranslateTransform ( ) ;
545+ selectionIndicator . RenderTransform = translateTransform ;
546+
547+ var toValue = RowPresenter ? . IsDetailsPanelVisible ?? false ? Math . Round ( - detailsHeight / 2 ) : 0 ; // move up or down
548+
549+ var animation = new DoubleAnimation
550+ {
551+ To = toValue ,
552+ Duration = new Duration ( TimeSpan . Zero )
553+ } ;
554+
555+ var storyboard = new Storyboard ( ) ;
556+ Storyboard . SetTarget ( animation , translateTransform ) ;
557+ Storyboard . SetTargetProperty ( animation , "Y" ) ; // vertical movement
558+ storyboard . Children . Add ( animation ) ;
559+
560+ storyboard . Begin ( ) ;
561+ }
562+ }
563+
565564 /// <summary>
566565 /// Ensures alternate colors are applied to the row.
567566 /// </summary>
0 commit comments