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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using Tango.SharedUI.Controls;
namespace Tango.PPC.Common.Controls
{
[ContentProperty(nameof(Elements))]
public class ImageGalleryControl : Control
{
private NavigationControl _navigationControl;
private DispatcherTimer _timer;
public int SelectedIndex
{
get { return (int)GetValue(SelectedIndexProperty); }
set { SetValue(SelectedIndexProperty, value); }
}
public static readonly DependencyProperty SelectedIndexProperty =
DependencyProperty.Register("SelectedIndex", typeof(int), typeof(ImageGalleryControl), new PropertyMetadata(0));
public ObservableCollection<FrameworkElement> Elements
{
get { return (ObservableCollection<FrameworkElement>)GetValue(ElementsProperty); }
set { SetValue(ElementsProperty, value); }
}
public static readonly DependencyProperty ElementsProperty =
DependencyProperty.Register("Elements", typeof(ObservableCollection<FrameworkElement>), typeof(ImageGalleryControl), new PropertyMetadata(null));
public Duration Duration
{
get { return (Duration)GetValue(DurationProperty); }
set { SetValue(DurationProperty, value); }
}
public static readonly DependencyProperty DurationProperty =
DependencyProperty.Register("Duration", typeof(Duration), typeof(ImageGalleryControl), new PropertyMetadata(new Duration(TimeSpan.FromSeconds(2))));
static ImageGalleryControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageGalleryControl), new FrameworkPropertyMetadata(typeof(ImageGalleryControl)));
}
public ImageGalleryControl()
{
Elements = new ObservableCollection<FrameworkElement>();
Loaded += ImageGalleryControl_Loaded;
_timer = new DispatcherTimer();
_timer.Tick += _timer_Tick;
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_navigationControl = GetTemplateChild("navigationControl") as NavigationControl;
}
private void ImageGalleryControl_Loaded(object sender, RoutedEventArgs e)
{
if (_navigationControl != null)
{
_navigationControl.Elements = Elements;
_timer.Interval = Duration.TimeSpan;
if (!DesignerProperties.GetIsInDesignMode(new DependencyObject()))
{
_timer.Start();
}
}
}
private void _timer_Tick(object sender, EventArgs e)
{
if (SelectedIndex < Elements.Count - 1)
{
SelectedIndex++;
}
else
{
SelectedIndex = 0;
}
}
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{
base.OnPreviewMouseDown(e);
_timer.Stop();
}
protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
{
base.OnPreviewMouseUp(e);
_timer.Start();
}
}
}
|