Browse Source

More anchor validation checks.

- Make sure an anchor is a descendent of the `ScrollContentPresenter` when added
- Ignore controls that are no longer descendents of the `ScrollContentPresenter` when evaluating
pull/4091/head
Steven Kirk 6 years ago
parent
commit
e36fbc6f22
  1. 27
      src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs

27
src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs

@ -207,6 +207,12 @@ namespace Avalonia.Controls.Presenters
/// <inheritdoc/>
void IScrollAnchorProvider.RegisterAnchorCandidate(IControl element)
{
if (!this.IsVisualAncestorOf(element))
{
throw new InvalidOperationException(
"An anchor control must be a visual descendent of the ScrollContentPresenter.");
}
_anchorCandidates ??= new List<IControl>();
_anchorCandidates.Add(element);
}
@ -531,14 +537,19 @@ namespace Avalonia.Controls.Presenters
private bool GetViewportBounds(IControl element, out Rect bounds)
{
// We want the bounds relative to the new Offset, regardless of whether the child
// control has actually been arranged to this offset yet, so translate first to the
// child control and then apply Offset rather than translating directly to this
// control.
var thisBounds = new Rect(Bounds.Size);
var childBounds = TranslateBounds(element, Child);
bounds = new Rect(childBounds.Position - Offset, childBounds.Size);
return bounds.Intersects(thisBounds);
if (TranslateBounds(element, Child, out var childBounds))
{
// We want the bounds relative to the new Offset, regardless of whether the child
// control has actually been arranged to this offset yet, so translate first to the
// child control and then apply Offset rather than translating directly to this
// control.
var thisBounds = new Rect(Bounds.Size);
bounds = new Rect(childBounds.Position - Offset, childBounds.Size);
return bounds.Intersects(thisBounds);
}
bounds = default;
return false;
}
private Rect TranslateBounds(IControl control, IControl to)

Loading…
Cancel
Save