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 Elements { get { return (ObservableCollection)GetValue(ElementsProperty); } set { SetValue(ElementsProperty, value); } } public static readonly DependencyProperty ElementsProperty = DependencyProperty.Register("Elements", typeof(ObservableCollection), 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(); 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(); } } }