@ -6,6 +6,7 @@ using System.Collections.Specialized;
using System.Linq ;
using Avalonia.Collections ;
using Avalonia.Controls.Presenters ;
using Avalonia.Controls.Primitives ;
using Avalonia.Controls.Templates ;
using Avalonia.Data ;
using Avalonia.Input ;
@ -1115,6 +1116,44 @@ namespace Avalonia.Controls.UnitTests
Assert . True ( container . IsVisible ) ;
}
[Fact]
public void ScrollIntoView_With_TargetRect_Outside_Viewport_Should_Scroll_To_Item ( )
{
using var app = App ( ) ;
var items = Enumerable . Range ( 0 , 1 0 1 ) . Select ( x = > new ItemWithHeight ( x , x * 1 0 0 + 1 ) ) ;
var itemTemplate = new FuncDataTemplate < ItemWithHeight > ( ( x , _ ) = >
new Border
{
Height = 1 0 ,
[!Layoutable.WidthProperty] = new Binding ( "Height" ) ,
} ) ;
var ( target , scroll , itemsControl ) = CreateTarget (
items : items ,
itemTemplate : itemTemplate ,
styles : new [ ]
{
new Style ( x = > x . OfType < ScrollViewer > ( ) )
{
Setters =
{
new Setter ( ScrollViewer . HorizontalScrollBarVisibilityProperty , ScrollBarVisibility . Visible ) ,
}
}
} ) ;
itemsControl . ContainerPrepared + = ( _ , ev ) = >
{
ev . Container . AddHandler ( Control . RequestBringIntoViewEvent , ( _ , e ) = >
{
var dataContext = e . TargetObject . DataContext as ItemWithHeight ;
e . TargetRect = new Rect ( dataContext . Height - 5 0 , 0 , 5 0 , 1 0 ) ;
} ) ;
} ;
target . ScrollIntoView ( 1 0 0 ) ;
Assert . Equal ( 9 9 0 1 , scroll . Offset . X ) ;
}
private static IReadOnlyList < int > GetRealizedIndexes ( VirtualizingStackPanel target , ItemsControl itemsControl )
{
return target . GetRealizedElements ( )