diff --git a/src/Avalonia.Controls/Avalonia.Controls.csproj b/src/Avalonia.Controls/Avalonia.Controls.csproj
index 9b5f8a9c1b..52e329189a 100644
--- a/src/Avalonia.Controls/Avalonia.Controls.csproj
+++ b/src/Avalonia.Controls/Avalonia.Controls.csproj
@@ -50,13 +50,14 @@
-
+
+
diff --git a/src/Avalonia.Controls/Generators/IItemContainerGenerator.cs b/src/Avalonia.Controls/Generators/IItemContainerGenerator.cs
index 8199333f47..2e02bdc647 100644
--- a/src/Avalonia.Controls/Generators/IItemContainerGenerator.cs
+++ b/src/Avalonia.Controls/Generators/IItemContainerGenerator.cs
@@ -16,7 +16,7 @@ namespace Avalonia.Controls.Generators
///
/// Gets the currently realized containers.
///
- IEnumerable Containers { get; }
+ IEnumerable Containers { get; }
///
/// Gets or sets the data template used to display the items in the control.
@@ -34,17 +34,17 @@ namespace Avalonia.Controls.Generators
event EventHandler Dematerialized;
///
- /// Creates container controls for a collection of items.
+ /// Creates a container control for an item.
///
- ///
- /// The index of the first item of the data in the containing collection.
+ ///
+ /// The index of the item of the data in the containing collection.
///
- /// The items.
+ /// The item.
/// An optional member selector.
/// The created controls.
- IEnumerable Materialize(
- int startingIndex,
- IEnumerable items,
+ ItemContainerInfo Materialize(
+ int index,
+ object item,
IMemberSelector selector);
///
@@ -55,7 +55,7 @@ namespace Avalonia.Controls.Generators
///
/// The the number of items to remove.
/// The removed containers.
- IEnumerable Dematerialize(int startingIndex, int count);
+ IEnumerable Dematerialize(int startingIndex, int count);
///
/// Inserts space for newly inserted containers in the index.
@@ -73,13 +73,13 @@ namespace Avalonia.Controls.Generators
///
/// The the number of items to remove.
/// The removed containers.
- IEnumerable RemoveRange(int startingIndex, int count);
+ IEnumerable RemoveRange(int startingIndex, int count);
///
/// Clears all created containers and returns the removed controls.
///
/// The removed controls.
- IEnumerable Clear();
+ IEnumerable Clear();
///
/// Gets the container control representing the item with the specified index.
diff --git a/src/Avalonia.Controls/Generators/ItemContainerEventArgs.cs b/src/Avalonia.Controls/Generators/ItemContainerEventArgs.cs
index 304e0a99fa..cd26b0ba83 100644
--- a/src/Avalonia.Controls/Generators/ItemContainerEventArgs.cs
+++ b/src/Avalonia.Controls/Generators/ItemContainerEventArgs.cs
@@ -19,7 +19,7 @@ namespace Avalonia.Controls.Generators
/// The container.
public ItemContainerEventArgs(
int startingIndex,
- ItemContainer container)
+ ItemContainerInfo container)
{
StartingIndex = startingIndex;
Containers = new[] { container };
@@ -32,7 +32,7 @@ namespace Avalonia.Controls.Generators
/// The containers.
public ItemContainerEventArgs(
int startingIndex,
- IList containers)
+ IList containers)
{
StartingIndex = startingIndex;
Containers = containers;
@@ -41,7 +41,7 @@ namespace Avalonia.Controls.Generators
///
/// Gets the containers.
///
- public IList Containers { get; }
+ public IList Containers { get; }
///
/// Gets the index of the first container in the source items.
diff --git a/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs b/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs
index 114d31c5a6..3bf69d910a 100644
--- a/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs
+++ b/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs
@@ -15,7 +15,7 @@ namespace Avalonia.Controls.Generators
///
public class ItemContainerGenerator : IItemContainerGenerator
{
- private List _containers = new List();
+ private List _containers = new List();
///
/// Initializes a new instance of the class.
@@ -29,7 +29,7 @@ namespace Avalonia.Controls.Generators
}
///
- public IEnumerable Containers => _containers.Where(x => x != null);
+ public IEnumerable Containers => _containers.Where(x => x != null);
///
public event EventHandler Materialized;
@@ -48,33 +48,24 @@ namespace Avalonia.Controls.Generators
public IControl Owner { get; }
///
- public IEnumerable Materialize(
- int startingIndex,
- IEnumerable items,
+ public ItemContainerInfo Materialize(
+ int index,
+ object item,
IMemberSelector selector)
{
- Contract.Requires(items != null);
+ var i = selector != null ? selector.Select(item) : item;
+ var container = new ItemContainerInfo(CreateContainer(i), item, index);
- int index = startingIndex;
- var result = new List();
+ AddContainer(container);
+ Materialized?.Invoke(this, new ItemContainerEventArgs(index, container));
- foreach (var item in items)
- {
- var i = selector != null ? selector.Select(item) : item;
- var container = new ItemContainer(CreateContainer(i), item, index++);
- result.Add(container);
- }
-
- AddContainers(result);
- Materialized?.Invoke(this, new ItemContainerEventArgs(startingIndex, result));
-
- return result.Where(x => x != null).ToList();
+ return container;
}
///
- public virtual IEnumerable Dematerialize(int startingIndex, int count)
+ public virtual IEnumerable Dematerialize(int startingIndex, int count)
{
- var result = new List();
+ var result = new List();
for (int i = startingIndex; i < startingIndex + count; ++i)
{
@@ -93,13 +84,13 @@ namespace Avalonia.Controls.Generators
///
public virtual void InsertSpace(int index, int count)
{
- _containers.InsertRange(index, Enumerable.Repeat(null, count));
+ _containers.InsertRange(index, Enumerable.Repeat(null, count));
}
///
- public virtual IEnumerable RemoveRange(int startingIndex, int count)
+ public virtual IEnumerable RemoveRange(int startingIndex, int count)
{
- List result = new List();
+ List result = new List();
if (startingIndex < _containers.Count)
{
@@ -112,10 +103,10 @@ namespace Avalonia.Controls.Generators
}
///
- public virtual IEnumerable Clear()
+ public virtual IEnumerable Clear()
{
var result = _containers.Where(x => x != null).ToList();
- _containers = new List();
+ _containers = new List();
if (result.Count > 0)
{
@@ -172,32 +163,29 @@ namespace Avalonia.Controls.Generators
}
///
- /// Adds a collection of containers to the index.
+ /// Adds a container to the index.
///
- /// The containers.
- protected void AddContainers(IList containers)
+ /// The container.
+ protected void AddContainer(ItemContainerInfo container)
{
- Contract.Requires(containers != null);
+ Contract.Requires(container != null);
- foreach (var c in containers)
+ while (_containers.Count < container.Index)
{
- while (_containers.Count < c.Index)
- {
- _containers.Add(null);
- }
+ _containers.Add(null);
+ }
- if (_containers.Count == c.Index)
- {
- _containers.Add(c);
- }
- else if (_containers[c.Index] == null)
- {
- _containers[c.Index] = c;
- }
- else
- {
- throw new InvalidOperationException("Container already created.");
- }
+ if (_containers.Count == container.Index)
+ {
+ _containers.Add(container);
+ }
+ else if (_containers[container.Index] == null)
+ {
+ _containers[container.Index] = container;
+ }
+ else
+ {
+ throw new InvalidOperationException("Container already created.");
}
}
@@ -207,7 +195,7 @@ namespace Avalonia.Controls.Generators
/// The first index.
/// The number of elements in the range.
/// The containers.
- protected IEnumerable GetContainerRange(int index, int count)
+ protected IEnumerable GetContainerRange(int index, int count)
{
return _containers.GetRange(index, count);
}
diff --git a/src/Avalonia.Controls/Generators/ItemContainer.cs b/src/Avalonia.Controls/Generators/ItemContainerInfo.cs
similarity index 91%
rename from src/Avalonia.Controls/Generators/ItemContainer.cs
rename to src/Avalonia.Controls/Generators/ItemContainerInfo.cs
index ed2e433a28..b0fcd2867e 100644
--- a/src/Avalonia.Controls/Generators/ItemContainer.cs
+++ b/src/Avalonia.Controls/Generators/ItemContainerInfo.cs
@@ -7,17 +7,17 @@ namespace Avalonia.Controls.Generators
/// Holds information about an item container generated by an
/// .
///
- public class ItemContainer
+ public class ItemContainerInfo
{
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// The container control.
/// The item that the container represents.
///
/// The index of the item in the collection.
///
- public ItemContainer(IControl container, object item, int index)
+ public ItemContainerInfo(IControl container, object item, int index)
{
ContainerControl = container;
Item = item;
diff --git a/src/Avalonia.Controls/Generators/TreeContainerIndex.cs b/src/Avalonia.Controls/Generators/TreeContainerIndex.cs
index b7a9bb2dc1..f58f7e019d 100644
--- a/src/Avalonia.Controls/Generators/TreeContainerIndex.cs
+++ b/src/Avalonia.Controls/Generators/TreeContainerIndex.cs
@@ -47,7 +47,7 @@ namespace Avalonia.Controls.Generators
Materialized?.Invoke(
this,
- new ItemContainerEventArgs(0, new ItemContainer(container, item, 0)));
+ new ItemContainerEventArgs(0, new ItemContainerInfo(container, item, 0)));
}
///
@@ -62,14 +62,14 @@ namespace Avalonia.Controls.Generators
Dematerialized?.Invoke(
this,
- new ItemContainerEventArgs(0, new ItemContainer(container, item, 0)));
+ new ItemContainerEventArgs(0, new ItemContainerInfo(container, item, 0)));
}
///
/// Removes a set of containers from the index.
///
/// The item containers.
- public void Remove(IEnumerable containers)
+ public void Remove(IEnumerable containers)
{
foreach (var container in containers)
{
diff --git a/src/Avalonia.Controls/Generators/TreeItemContainerGenerator.cs b/src/Avalonia.Controls/Generators/TreeItemContainerGenerator.cs
index 681bea865a..68e410ae19 100644
--- a/src/Avalonia.Controls/Generators/TreeItemContainerGenerator.cs
+++ b/src/Avalonia.Controls/Generators/TreeItemContainerGenerator.cs
@@ -99,20 +99,20 @@ namespace Avalonia.Controls.Generators
}
}
- public override IEnumerable Clear()
+ public override IEnumerable Clear()
{
var items = base.Clear();
Index.Remove(items);
return items;
}
- public override IEnumerable Dematerialize(int startingIndex, int count)
+ public override IEnumerable Dematerialize(int startingIndex, int count)
{
Index.Remove(GetContainerRange(startingIndex, count));
return base.Dematerialize(startingIndex, count);
}
- public override IEnumerable RemoveRange(int startingIndex, int count)
+ public override IEnumerable RemoveRange(int startingIndex, int count)
{
Index.Remove(GetContainerRange(startingIndex, count));
return base.RemoveRange(startingIndex, count);
diff --git a/src/Avalonia.Controls/ItemVirtualizationMode.cs b/src/Avalonia.Controls/ItemVirtualizationMode.cs
new file mode 100644
index 0000000000..f17e8c07ad
--- /dev/null
+++ b/src/Avalonia.Controls/ItemVirtualizationMode.cs
@@ -0,0 +1,21 @@
+// Copyright (c) The Avalonia Project. All rights reserved.
+// Licensed under the MIT license. See licence.md file in the project root for full license information.
+
+namespace Avalonia.Controls
+{
+ ///
+ /// Describes the item virtualization method to use for a list.
+ ///
+ public enum ItemVirtualizationMode
+ {
+ ///
+ /// Do not virtualize items.
+ ///
+ None,
+
+ ///
+ /// Virtualize items without smooth scrolling.
+ ///
+ Simple,
+ }
+}
diff --git a/src/Avalonia.Controls/Presenters/CarouselPresenter.cs b/src/Avalonia.Controls/Presenters/CarouselPresenter.cs
index a4f9c0cb43..29488c8b80 100644
--- a/src/Avalonia.Controls/Presenters/CarouselPresenter.cs
+++ b/src/Avalonia.Controls/Presenters/CarouselPresenter.cs
@@ -175,12 +175,8 @@ namespace Avalonia.Controls.Presenters
if (container == null)
{
var item = Items.Cast