Skip to content

Commit

Permalink
Use NonVirtualizingLayoutContext.
Browse files Browse the repository at this point in the history
- Add and use `NonVirtualizingLayoutContext` in `NonVirtualizingLayout`
- Return -1 instead of throwing if element is not a child of `ItemsRepeater`

Ported from microsoft/microsoft-ui-xaml@22adf4d
  • Loading branch information
grokys committed Jan 9, 2020
1 parent 261e477 commit 1f46076
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Avalonia.Controls/Repeater/ViewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ public int GetElementIndex(VirtualizationInfo virtInfo)
{
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;
Expand Down
8 changes: 4 additions & 4 deletions src/Avalonia.Layout/NonVirtualizingLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public sealed override void UninitializeForContext(LayoutContext context)
/// <inheritdoc/>
public sealed override Size Measure(LayoutContext context, Size availableSize)
{
return MeasureOverride((VirtualizingLayoutContext)context, availableSize);
return MeasureOverride((NonVirtualizingLayoutContext)context, availableSize);
}

/// <inheritdoc/>
Expand All @@ -49,7 +49,7 @@ public sealed override Size Arrange(LayoutContext context, Size finalSize)
/// The context object that facilitates communication between the layout and its host
/// container.
/// </param>
protected virtual void InitializeForContextCore(VirtualizingLayoutContext context)
protected virtual void InitializeForContextCore(LayoutContext context)
{
}

Expand All @@ -61,7 +61,7 @@ protected virtual void InitializeForContextCore(VirtualizingLayoutContext contex
/// The context object that facilitates communication between the layout and its host
/// container.
/// </param>
protected virtual void UninitializeForContextCore(VirtualizingLayoutContext context)
protected virtual void UninitializeForContextCore(LayoutContext context)
{
}

Expand All @@ -83,7 +83,7 @@ protected virtual void UninitializeForContextCore(VirtualizingLayoutContext cont
/// of the allocated sizes for child objects or based on other considerations such as a
/// fixed container size.
/// </returns>
protected abstract Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize);
protected abstract Size MeasureOverride(NonVirtualizingLayoutContext context, Size availableSize);

/// <summary>
/// When implemented in a derived class, provides the behavior for the "Arrange" pass of
Expand Down
11 changes: 11 additions & 0 deletions src/Avalonia.Layout/NonVirtualizingLayoutContext.cs
Original file line number Diff line number Diff line change
@@ -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
{
}
}

0 comments on commit 1f46076

Please sign in to comment.