|
| 1 | +namespace DevWinUI; |
| 2 | + |
| 3 | +public sealed partial class CarouselView |
| 4 | +{ |
| 5 | + public int SelectedIndex |
| 6 | + { |
| 7 | + get { return (int)GetValue(SelectedIndexProperty); } |
| 8 | + set { SetValue(SelectedIndexProperty, value); } |
| 9 | + } |
| 10 | + |
| 11 | + public static readonly DependencyProperty SelectedIndexProperty = |
| 12 | + DependencyProperty.Register(nameof(SelectedIndex), typeof(int), typeof(CarouselView), new PropertyMetadata(-1, (s, e) =>{})); |
| 13 | + public double ItemWidth |
| 14 | + { |
| 15 | + get { return (double)GetValue(ItemWidthProperty); } |
| 16 | + set { SetValue(ItemWidthProperty, value); } |
| 17 | + } |
| 18 | + |
| 19 | + public static readonly DependencyProperty ItemWidthProperty = |
| 20 | + DependencyProperty.Register(nameof(ItemWidth), typeof(double), typeof(CarouselView), new PropertyMetadata(300.00d)); |
| 21 | + |
| 22 | + public List<ICarouselViewItemSource> ItemImageSource |
| 23 | + { |
| 24 | + get { return (List<ICarouselViewItemSource>)GetValue(ItemImageSourceProperty); } |
| 25 | + set |
| 26 | + { |
| 27 | + SetValue(ItemImageSourceProperty, value); |
| 28 | + this.SetItemsImageSource(); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + public static readonly DependencyProperty ItemImageSourceProperty = |
| 33 | + DependencyProperty.Register(nameof(ItemImageSource), typeof(List<ICarouselViewItemSource>), typeof(CarouselView), new PropertyMetadata(null, (s, e) => |
| 34 | + { |
| 35 | + var carousel = s as CarouselView; |
| 36 | + if (carousel != null) |
| 37 | + { |
| 38 | + carousel.SetItemsImageSource(); |
| 39 | + } |
| 40 | + })); |
| 41 | + public bool IsAutoSwitchEnabled |
| 42 | + { |
| 43 | + get { return (bool)GetValue(IsAutoSwitchEnableProperty); } |
| 44 | + set { SetValue(IsAutoSwitchEnableProperty, value); } |
| 45 | + } |
| 46 | + |
| 47 | + public static readonly DependencyProperty IsAutoSwitchEnableProperty = |
| 48 | + DependencyProperty.Register(nameof(IsAutoSwitchEnabled), typeof(bool), typeof(CarouselView), new PropertyMetadata(true, (s, e) => |
| 49 | + { |
| 50 | + if (e.NewValue != e.OldValue) |
| 51 | + { |
| 52 | + if ((bool)e.NewValue) |
| 53 | + { |
| 54 | + (s as CarouselView)._dispatcherTimer.Start(); |
| 55 | + } |
| 56 | + else |
| 57 | + { |
| 58 | + (s as CarouselView)._dispatcherTimer.Stop(); |
| 59 | + } |
| 60 | + } |
| 61 | + })); |
| 62 | + |
| 63 | + public TimeSpan AutoSwitchInterval |
| 64 | + { |
| 65 | + get { return (TimeSpan)GetValue(AutoSwitchIntervalProperty); } |
| 66 | + set { SetValue(AutoSwitchIntervalProperty, value); } |
| 67 | + } |
| 68 | + |
| 69 | + public static readonly DependencyProperty AutoSwitchIntervalProperty = |
| 70 | + DependencyProperty.Register(nameof(AutoSwitchInterval), typeof(TimeSpan), typeof(CarouselView), new PropertyMetadata(new TimeSpan(0, 0, 7), (s, e) => |
| 71 | + { |
| 72 | + if (e.NewValue != e.OldValue) |
| 73 | + { |
| 74 | + (s as CarouselView)._dispatcherTimer.Interval = (TimeSpan)e.NewValue; |
| 75 | + (s as CarouselView)._dispatcherTimer.Start(); |
| 76 | + } |
| 77 | + })); |
| 78 | +} |
0 commit comments