diff --git a/src/Perspex.Controls/Carousel.cs b/src/Perspex.Controls/Carousel.cs
index fda48d0b42..36e586321c 100644
--- a/src/Perspex.Controls/Carousel.cs
+++ b/src/Perspex.Controls/Carousel.cs
@@ -14,6 +14,12 @@ namespace Perspex.Controls
///
public class Carousel : SelectingItemsControl
{
+ ///
+ /// Defines the property.
+ ///
+ public static readonly StyledProperty IsVirtualizedProperty =
+ PerspexProperty.Register(nameof(IsVirtualized), true);
+
///
/// Defines the property.
///
@@ -35,6 +41,18 @@ namespace Perspex.Controls
SelectionModeProperty.OverrideDefaultValue(SelectionMode.AlwaysSelected);
ItemsPanelProperty.OverrideDefaultValue(PanelTemplate);
}
+
+ ///
+ /// Gets or sets a value indicating whether the items in the carousel are virtualized.
+ ///
+ ///
+ /// When the carousel is virtualized, only the active page is held in memory.
+ ///
+ public bool IsVirtualized
+ {
+ get { return GetValue(IsVirtualizedProperty); }
+ set { SetValue(IsVirtualizedProperty, value); }
+ }
///
/// Gets or sets the transition to use when moving between pages.
diff --git a/src/Perspex.Controls/Generators/ItemContainerGenerator.cs b/src/Perspex.Controls/Generators/ItemContainerGenerator.cs
index 0e30518346..a162ce08de 100644
--- a/src/Perspex.Controls/Generators/ItemContainerGenerator.cs
+++ b/src/Perspex.Controls/Generators/ItemContainerGenerator.cs
@@ -29,7 +29,7 @@ namespace Perspex.Controls.Generators
}
///
- public IEnumerable Containers => _containers;
+ public IEnumerable Containers => _containers.Where(x => x != null);
///
public event EventHandler Materialized;
diff --git a/src/Perspex.Controls/Presenters/CarouselPresenter.cs b/src/Perspex.Controls/Presenters/CarouselPresenter.cs
index 8d25729e74..cde7bcf823 100644
--- a/src/Perspex.Controls/Presenters/CarouselPresenter.cs
+++ b/src/Perspex.Controls/Presenters/CarouselPresenter.cs
@@ -20,6 +20,12 @@ namespace Perspex.Controls.Presenters
///
public class CarouselPresenter : Control, IItemsPresenter
{
+ ///
+ /// Defines the property.
+ ///
+ public static readonly StyledProperty IsVirtualizedProperty =
+ Carousel.IsVirtualizedProperty.AddOwner();
+
///
/// Defines the property.
///
@@ -96,6 +102,18 @@ namespace Perspex.Controls.Presenters
}
}
+ ///
+ /// Gets or sets a value indicating whether the items in the carousel are virtualized.
+ ///
+ ///
+ /// When the carousel is virtualized, only the active page is held in memory.
+ ///
+ public bool IsVirtualized
+ {
+ get { return GetValue(IsVirtualizedProperty); }
+ set { SetValue(IsVirtualizedProperty, value); }
+ }
+
///
/// Gets or sets the items to display.
///
@@ -212,13 +230,17 @@ namespace Perspex.Controls.Presenters
if (toIndex != -1)
{
var item = Items.Cast