Browse Source

Use NonVirtualizingLayoutContext.

- Add and use `NonVirtualizingLayoutContext` in `NonVirtualizingLayout`
- Return -1 instead of throwing if element is not a child of `ItemsRepeater`

Ported from 22adf4dc62
pull/3424/head
Steven Kirk 6 years ago
parent
commit
1f46076f16
  1. 3
      src/Avalonia.Controls/Repeater/ViewManager.cs
  2. 8
      src/Avalonia.Layout/NonVirtualizingLayout.cs
  3. 11
      src/Avalonia.Layout/NonVirtualizingLayoutContext.cs

3
src/Avalonia.Controls/Repeater/ViewManager.cs

@ -200,7 +200,8 @@ namespace Avalonia.Controls
{ {
if (virtInfo == null) if (virtInfo == null)
{ {
throw new ArgumentException("Element is not a child of this ItemsRepeater."); //Element is not a child of this ItemsRepeater.
return -1;
} }
return virtInfo.IsRealized || virtInfo.IsInUniqueIdResetPool ? virtInfo.Index : -1; return virtInfo.IsRealized || virtInfo.IsInUniqueIdResetPool ? virtInfo.Index : -1;

8
src/Avalonia.Layout/NonVirtualizingLayout.cs

@ -32,7 +32,7 @@ namespace Avalonia.Layout
/// <inheritdoc/> /// <inheritdoc/>
public sealed override Size Measure(LayoutContext context, Size availableSize) public sealed override Size Measure(LayoutContext context, Size availableSize)
{ {
return MeasureOverride((VirtualizingLayoutContext)context, availableSize); return MeasureOverride((NonVirtualizingLayoutContext)context, availableSize);
} }
/// <inheritdoc/> /// <inheritdoc/>
@ -49,7 +49,7 @@ namespace Avalonia.Layout
/// The context object that facilitates communication between the layout and its host /// The context object that facilitates communication between the layout and its host
/// container. /// container.
/// </param> /// </param>
protected virtual void InitializeForContextCore(VirtualizingLayoutContext context) protected virtual void InitializeForContextCore(LayoutContext context)
{ {
} }
@ -61,7 +61,7 @@ namespace Avalonia.Layout
/// The context object that facilitates communication between the layout and its host /// The context object that facilitates communication between the layout and its host
/// container. /// container.
/// </param> /// </param>
protected virtual void UninitializeForContextCore(VirtualizingLayoutContext context) protected virtual void UninitializeForContextCore(LayoutContext context)
{ {
} }
@ -83,7 +83,7 @@ namespace Avalonia.Layout
/// of the allocated sizes for child objects or based on other considerations such as a /// of the allocated sizes for child objects or based on other considerations such as a
/// fixed container size. /// fixed container size.
/// </returns> /// </returns>
protected abstract Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize); protected abstract Size MeasureOverride(NonVirtualizingLayoutContext context, Size availableSize);
/// <summary> /// <summary>
/// When implemented in a derived class, provides the behavior for the "Arrange" pass of /// When implemented in a derived class, provides the behavior for the "Arrange" pass of

11
src/Avalonia.Layout/NonVirtualizingLayoutContext.cs

@ -0,0 +1,11 @@
// This source file is adapted from the WinUI project.
// (https://github.com/microsoft/microsoft-ui-xaml)
//
// Licensed to The Avalonia Project under MIT License, courtesy of The .NET Foundation.
namespace Avalonia.Layout
{
public abstract class NonVirtualizingLayoutContext : LayoutContext
{
}
}
Loading…
Cancel
Save