A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

100 lines
3.2 KiB

// 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.
using Avalonia.Animation;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Controls.Utils;
using Avalonia.Input;
namespace Avalonia.Controls
{
/// <summary>
/// An items control that displays its items as pages that fill the control.
/// </summary>
public class Carousel : SelectingItemsControl
{
/// <summary>
/// Defines the <see cref="IsVirtualized"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsVirtualizedProperty =
AvaloniaProperty.Register<Carousel, bool>(nameof(IsVirtualized), true);
/// <summary>
/// Defines the <see cref="Transition"/> property.
/// </summary>
public static readonly StyledProperty<IPageTransition> TransitionProperty =
AvaloniaProperty.Register<Carousel, IPageTransition>("Transition");
/// <summary>
/// The default value of <see cref="ItemsControl.ItemsPanelProperty"/> for
/// <see cref="Carousel"/>.
/// </summary>
private static readonly ITemplate<IPanel> PanelTemplate =
new FuncTemplate<IPanel>(() => new Panel());
/// <summary>
/// Initializes static members of the <see cref="Carousel"/> class.
/// </summary>
static Carousel()
{
SelectionModeProperty.OverrideDefaultValue<Carousel>(SelectionMode.AlwaysSelected);
ItemsPanelProperty.OverrideDefaultValue<Carousel>(PanelTemplate);
}
/// <summary>
/// Gets or sets a value indicating whether the items in the carousel are virtualized.
/// </summary>
/// <remarks>
/// When the carousel is virtualized, only the active page is held in memory.
/// </remarks>
public bool IsVirtualized
{
get { return GetValue(IsVirtualizedProperty); }
set { SetValue(IsVirtualizedProperty, value); }
}
/// <summary>
/// Gets or sets the transition to use when moving between pages.
/// </summary>
public IPageTransition Transition
{
get { return GetValue(TransitionProperty); }
set { SetValue(TransitionProperty, value); }
}
/// <summary>
/// Moves to the next item in the carousel.
/// </summary>
public void Next()
{
if (SelectedIndex < Items.Count() - 1)
{
++SelectedIndex;
}
}
/// <summary>
/// Moves to the previous item in the carousel.
/// </summary>
public void Previous()
{
if (SelectedIndex > 0)
{
--SelectedIndex;
}
}
/// <inheritdoc/>
protected override void OnKeyDown(KeyEventArgs e)
{
// Ignore key presses.
}
/// <inheritdoc/>
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
// Ignore pointer presses.
}
}
}