-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarouselPanel.cs
More file actions
86 lines (73 loc) · 3.37 KB
/
CarouselPanel.cs
File metadata and controls
86 lines (73 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media;
namespace PlazaConnectivityChecker
{
public class CarouselPanel : Panel
{
private bool _eventHooked = false;
protected override Size MeasureOverride(Size availableSize)
{
if (!_eventHooked)
{
var listBox = GetListBox();
if (listBox != null)
{
listBox.SelectionChanged += (sender, e) => InvalidateArrange();
_eventHooked = true;
}
}
foreach (UIElement child in Children)
child.Measure(new Size(300, 500));
base.MeasureOverride(availableSize);
return availableSize;
}
protected override Size ArrangeOverride(Size finalSize)
{
var listBox = GetListBox();
if (listBox == null) return base.ArrangeOverride(finalSize);
if (listBox.SelectedIndex < 0) listBox.SelectedIndex = 0;
int selectedIndex = listBox.SelectedIndex;
int rightCount = Children.Count - selectedIndex;
int leftCount = selectedIndex - 1;
double top = (finalSize.Height - 500)/2;
int zIndex = 10000;
double center = finalSize.Width/2;
center -= 150;
for (int leftCounter = 0; leftCounter < selectedIndex; leftCounter++ )
{
var left = center - ((selectedIndex - leftCounter) * 80) - 80;
var finalRect = new Rect(left, top, 300, 500);
Children[leftCounter].Arrange(finalRect);
CarouselPanel.SetAngle(Children[leftCounter], -65);
Panel.SetZIndex(Children[leftCounter], zIndex);
zIndex++;
}
for (int rightCounter = Children.Count-1; rightCounter > selectedIndex; rightCounter--)
{
var left = center + ((rightCounter - selectedIndex) * 80) + 80;
var finalRect = new Rect(left, top, 300, 500);
Children[rightCounter].Arrange(finalRect);
CarouselPanel.SetAngle(Children[rightCounter], 65);
Panel.SetZIndex(Children[rightCounter], zIndex);
zIndex++;
}
Children[selectedIndex].Arrange(new Rect(center, top, 300, 500));
CarouselPanel.SetAngle(Children[selectedIndex], 0);
Panel.SetZIndex(Children[selectedIndex], 11000);
return base.ArrangeOverride(finalSize);
}
private ListBox GetListBox()
{
return VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(this))) as ListBox;
}
public int Angle
{
get { return (int)GetValue(AngleProperty); }
set { SetValue(AngleProperty, value); }
}
public static readonly DependencyProperty AngleProperty = DependencyProperty.RegisterAttached("Angle", typeof(int), typeof(CarouselPanel), new UIPropertyMetadata(0));
public static void SetAngle(DependencyObject target, int value) { target.SetValue(CarouselPanel.AngleProperty, value); }
public static int GetAngle(DependencyObject target) { return (int)target.GetValue(CarouselPanel.AngleProperty); }
}
}