Browse Source

FIx bringing an item into view.

pull/4091/head
Steven Kirk 6 years ago
parent
commit
6c19e729a3
  1. 6
      src/Avalonia.Controls/Repeater/ItemsRepeater.cs
  2. 40
      src/Avalonia.Controls/Repeater/ViewportManager.cs

6
src/Avalonia.Controls/Repeater/ItemsRepeater.cs

@ -80,6 +80,7 @@ namespace Avalonia.Controls
static ItemsRepeater()
{
ClipToBoundsProperty.OverrideDefaultValue<ItemsRepeater>(true);
RequestBringIntoViewEvent.AddClassHandler<ItemsRepeater>((x, e) => x.OnRequestBringIntoView(e));
}
/// <summary>
@ -743,6 +744,11 @@ namespace Avalonia.Controls
}
}
private void OnRequestBringIntoView(RequestBringIntoViewEventArgs e)
{
_viewportManager.OnBringIntoViewRequested(e);
}
private void InvalidateMeasureForLayout(object sender, EventArgs e) => InvalidateMeasure();
private void InvalidateArrangeForLayout(object sender, EventArgs e) => InvalidateArrange();

40
src/Avalonia.Controls/Repeater/ViewportManager.cs

@ -306,8 +306,11 @@ namespace Avalonia.Controls
public void OnMakeAnchor(IControl anchor, bool isAnchorOutsideRealizedRange)
{
_makeAnchorElement = anchor;
_isAnchorOutsideRealizedRange = isAnchorOutsideRealizedRange;
if (_makeAnchorElement != anchor)
{
_makeAnchorElement = anchor;
_isAnchorOutsideRealizedRange = isAnchorOutsideRealizedRange;
}
}
public void OnBringIntoViewRequested(RequestBringIntoViewEventArgs args)
@ -334,13 +337,12 @@ namespace Avalonia.Controls
////}
}
// Register to rendering event to go back to how things were before where any child can be the anchor.
_isBringIntoViewInProgress = true;
////if (!m_renderingToken)
////{
//// winrt::Windows::UI::Xaml::Media::CompositionTarget compositionTarget{ nullptr };
//// m_renderingToken = compositionTarget.Rendering(winrt::auto_revoke, { this, &ViewportManagerWithPlatformFeatures::OnCompositionTargetRendering });
////}
// Register action to go back to how things were before where any child can be the anchor.
if (!_isBringIntoViewInProgress)
{
_isBringIntoViewInProgress = true;
Dispatcher.UIThread.Post(OnCompositionTargetRendering);
}
}
}
@ -362,6 +364,26 @@ namespace Avalonia.Controls
return targetChild;
}
private void OnCompositionTargetRendering()
{
_isBringIntoViewInProgress = false;
_makeAnchorElement = null;
// Now that the item has been brought into view, we can let the anchor provider pick a new anchor.
////foreach (var child in _owner.Children)
////{
//// if (!child.CanBeScrollAnchor)
//// {
//// var info = ItemsRepeater.GetVirtualizationInfo(child);
//// if (info.IsRealized && info.IsHeldByLayout)
//// {
//// child.CanBeScrollAnchor = true;
//// }
//// }
////}
}
public void ResetScrollers()
{
_scroller = null;

Loading…
Cancel
Save