فهرست منبع

Make Carousel demo buttons work.

Steven Kirk 10 سال پیش
والد
کامیت
ce1ef2fd89
2فایلهای تغییر یافته به همراه30 افزوده شده و 3 حذف شده
  1. 8 3
      samples/ControlCatalog/Pages/CarouselPage.paml.cs
  2. 22 0
      src/Perspex.Controls/Carousel.cs

+ 8 - 3
samples/ControlCatalog/Pages/CarouselPage.paml.cs

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

+ 22 - 0
src/Perspex.Controls/Carousel.cs

@@ -44,6 +44,28 @@ namespace Perspex.Controls
             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)
         {