Skip to content

Commit 93c62db

Browse files
committed
Add EasyCarouselPanel
1 parent a1aff13 commit 93c62db

File tree

12 files changed

+13132
-21764
lines changed

12 files changed

+13132
-21764
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Install-Package DevWinUI
135135
## 🔥 DevWinUI.Controls 🔥
136136
### ⚡ What’s Inside? ⚡
137137

138+
- ✨ EasyCarouselPanel
138139
- ✨ Stars
139140
- ✨ BannerView
140141
- ✨ AudioWave
@@ -315,6 +316,9 @@ Install-Package DevWinUI.ContextMenu
315316

316317
## 🕰️ History 🕰️
317318

319+
### EasyCarouselPanel
320+
![EasyCarouselPanel](https://raw.githubusercontent.com/ghost1372/DevWinUI-Resources/refs/heads/main/DevWinUI-Docs/EasyCarouselPanel.gif)
321+
318322
### Stars
319323
![Stars](https://raw.githubusercontent.com/ghost1372/DevWinUI-Resources/refs/heads/main/DevWinUI-Docs/Stars.gif)
320324

dev/DevWinUI.Controls/Controls/Win2DAndComposition/BannerView/BannerView.Properties.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace DevWinUI;
1+
using static DevWinUI.EasyCarouselPanel;
2+
3+
namespace DevWinUI;
24

35
public partial class BannerView
46
{
@@ -8,7 +10,7 @@ public bool IsPerspectiveEnable
810
set { SetValue(IsPerspectiveEnableProperty, value); }
911
}
1012
public static readonly DependencyProperty IsPerspectiveEnableProperty =
11-
DependencyProperty.Register("IsPerspectiveEnable", typeof(bool), typeof(BannerView), new PropertyMetadata(false, (s, a) =>
13+
DependencyProperty.Register(nameof(IsPerspectiveEnable), typeof(bool), typeof(BannerView), new PropertyMetadata(false, (s, a) =>
1214
{
1315
if (a.NewValue != a.OldValue)
1416
{
@@ -25,7 +27,7 @@ public bool IsScaleEnable
2527
set { SetValue(IsScaleEnableProperty, value); }
2628
}
2729
public static readonly DependencyProperty IsScaleEnableProperty =
28-
DependencyProperty.Register("IsScaleEnable", typeof(bool), typeof(BannerView), new PropertyMetadata(false, (s, a) =>
30+
DependencyProperty.Register(nameof(IsScaleEnable), typeof(bool), typeof(BannerView), new PropertyMetadata(false, (s, a) =>
2931
{
3032
if (a.NewValue != a.OldValue)
3133
{
@@ -43,7 +45,7 @@ public double ItemsSpacing
4345
}
4446

4547
public static readonly DependencyProperty ItemsSpacingProperty =
46-
DependencyProperty.Register("ItemsSpacing", typeof(double), typeof(BannerView), new PropertyMetadata(0d, (s, a) =>
48+
DependencyProperty.Register(nameof(ItemsSpacing), typeof(double), typeof(BannerView), new PropertyMetadata(0d, (s, a) =>
4749
{
4850
if (a.NewValue != a.OldValue)
4951
{
@@ -89,4 +91,13 @@ private static void OnIntervalChanged(DependencyObject d, DependencyPropertyChan
8991
ctl.timer?.Interval = timeSpan;
9092
}
9193
}
94+
95+
public CarouselShiftingDirection ShiftingDirection
96+
{
97+
get { return (CarouselShiftingDirection)GetValue(ShiftingDirectionProperty); }
98+
set { SetValue(ShiftingDirectionProperty, value); }
99+
}
100+
101+
public static readonly DependencyProperty ShiftingDirectionProperty =
102+
DependencyProperty.Register(nameof(ShiftingDirection), typeof(CarouselShiftingDirection), typeof(BannerView), new PropertyMetadata(CarouselShiftingDirection.Forward, null));
92103
}

dev/DevWinUI.Controls/Controls/Win2DAndComposition/BannerView/BannerView.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Reflection;
2-
using Microsoft.UI.Xaml.Controls;
3-
using Windows.Foundation.Metadata;
1+
using Windows.Foundation.Metadata;
42

53
namespace DevWinUI;
64

@@ -29,7 +27,6 @@ public partial class BannerView : FlipView
2927

3028
protected bool IsLoaded { get; private set; }
3129
private DispatcherTimer timer;
32-
private bool isForward = true;
3330
public BannerView()
3431
{
3532
this.DefaultStyleKey = typeof(BannerView);
@@ -116,7 +113,7 @@ public void PlayShuffleForward()
116113
if (!AutoShuffle)
117114
return;
118115

119-
isForward = true;
116+
ShiftingDirection = CarouselShiftingDirection.Forward;
120117
StartShuffleInternal();
121118
}
122119

@@ -125,7 +122,7 @@ public void PlayShuffleBackward()
125122
if (!AutoShuffle)
126123
return;
127124

128-
isForward = false;
125+
ShiftingDirection = CarouselShiftingDirection.Backward;
129126
StartShuffleInternal();
130127
}
131128

@@ -135,10 +132,15 @@ private void StartShuffleInternal()
135132
}
136133
private void Timer_Tick(object sender, object e)
137134
{
138-
if (isForward)
139-
SelectedIndex++;
140-
else
141-
SelectedIndex--;
135+
switch (ShiftingDirection)
136+
{
137+
case CarouselShiftingDirection.Forward:
138+
SelectedIndex++;
139+
break;
140+
case CarouselShiftingDirection.Backward:
141+
SelectedIndex--;
142+
break;
143+
}
142144
}
143145

144146
private void ScrollingHost_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace DevWinUI;
2+
3+
public enum CarouselShiftingDirection
4+
{
5+
Forward = 0,
6+
Backward = 1
7+
}

0 commit comments

Comments
 (0)