Browse Source

Make Carousel demo buttons work.

pull/386/head
Steven Kirk 11 years ago
parent
commit
ce1ef2fd89
  1. 11
      samples/ControlCatalog/Pages/CarouselPage.paml.cs
  2. 22
      src/Perspex.Controls/Carousel.cs

11
samples/ControlCatalog/Pages/CarouselPage.paml.cs

@ -5,18 +5,23 @@ namespace ControlCatalog.Pages
{ {
public class CarouselPage : UserControl public class CarouselPage : UserControl
{ {
private Carousel carousel; private Carousel _carousel;
private Button left; private Button _left;
private Button right; private Button _right;
public CarouselPage() public CarouselPage()
{ {
this.InitializeComponent(); this.InitializeComponent();
_left.Click += (s, e) => _carousel.Previous();
_right.Click += (s, e) => _carousel.Next();
} }
private void InitializeComponent() private void InitializeComponent()
{ {
PerspexXamlLoader.Load(this); PerspexXamlLoader.Load(this);
_carousel = this.FindControl<Carousel>("carousel");
_left = this.FindControl<Button>("left");
_right = this.FindControl<Button>("right");
} }
} }
} }

22
src/Perspex.Controls/Carousel.cs

@ -44,6 +44,28 @@ namespace Perspex.Controls
set { SetValue(TransitionProperty, value); } 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/> /// <inheritdoc/>
protected override void OnKeyDown(KeyEventArgs e) protected override void OnKeyDown(KeyEventArgs e)
{ {

Loading…
Cancel
Save