@ -265,6 +265,16 @@ namespace Avalonia.Controls
}
}
protected override void OnItemsControlChanged ( ItemsControl ? oldValue )
{
base . OnItemsControlChanged ( oldValue ) ;
if ( oldValue is not null )
oldValue . PropertyChanged - = OnItemsControlPropertyChanged ;
if ( ItemsControl is not null )
ItemsControl . PropertyChanged + = OnItemsControlPropertyChanged ;
}
protected override IInputElement ? GetControl ( NavigationDirection direction , IInputElement ? from , bool wrap )
{
var count = Items . Count ;
@ -378,7 +388,7 @@ namespace Avalonia.Controls
var scrollToElement = GetOrCreateElement ( items , index ) ;
scrollToElement . Measure ( Size . Infinity ) ;
// Get the expected position of the elment and put it in place.
// Get the expected position of the ele ment and put it in place.
var anchorU = _ realizedElements . GetOrEstimateElementU ( index , ref _l astEstimatedElementSizeU ) ;
var rect = Orientation = = Orientation . Horizontal ?
new Rect ( anchorU , 0 , scrollToElement . DesiredSize . Width , scrollToElement . DesiredSize . Height ) :
@ -661,6 +671,7 @@ namespace Avalonia.Controls
private void RecycleElement ( Control element , int index )
{
Debug . Assert ( ItemsControl is not null ) ;
Debug . Assert ( ItemContainerGenerator is not null ) ;
_ scrollAnchorProvider ? . UnregisterAnchorCandidate ( element ) ;
@ -675,11 +686,10 @@ namespace Avalonia.Controls
{
element . IsVisible = false ;
}
else if ( element . IsKeyboardFocusWithin )
else if ( KeyboardNavigation . GetTabOnceActiveElement ( ItemsControl ) = = element )
{
_f ocusedElement = element ;
_f ocusedIndex = index ;
_f ocusedElement . LostFocus + = OnUnrealizedFocusedElementLostFocus ;
}
else
{
@ -746,15 +756,17 @@ namespace Avalonia.Controls
}
}
private void OnUnrealizedFocusedElementLostFocus ( object? sender , Rout edEventArgs e )
private void OnItemsControlPropertyChanged ( object? sender , AvaloniaPropertyChang edEventArgs e )
{
if ( _f ocusedElement is null | | sender ! = _f ocusedElement )
return ;
_f ocusedElement . LostFocus - = OnUnrealizedFocusedElementLostFocus ;
RecycleElement ( _f ocusedElement , _f ocusedIndex ) ;
_f ocusedElement = null ;
_f ocusedIndex = - 1 ;
if ( _f ocusedElement is not null & &
e . Property = = KeyboardNavigation . TabOnceActiveElementProperty & &
e . GetOldValue < IInputElement ? > ( ) = = _f ocusedElement )
{
// TabOnceActiveElement has moved away from _focusedElement so we can recycle it.
RecycleElement ( _f ocusedElement , _f ocusedIndex ) ;
_f ocusedElement = null ;
_f ocusedIndex = - 1 ;
}
}
/// <inheritdoc/>