aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/ImageGalleryControl.cs
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2020-11-09 23:34:01 +0200
committerShlomo Hecht <shlomo@twine-s.com>2020-11-09 23:34:01 +0200
commite7cbb2ad47498bb072ee293baaf7fc9e2999fbec (patch)
tree073fe0b1fee57246dd639c2f21dc6b175e197a23 /Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/ImageGalleryControl.cs
parentf42acf4a2513bfb156f3323d2cd9dadf67809220 (diff)
parent313970208cf06fe7925e41a9479e619fa1aca7f6 (diff)
downloadTango-e7cbb2ad47498bb072ee293baaf7fc9e2999fbec.tar.gz
Tango-e7cbb2ad47498bb072ee293baaf7fc9e2999fbec.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/ImageGalleryControl.cs')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/ImageGalleryControl.cs114
1 files changed, 114 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/ImageGalleryControl.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/ImageGalleryControl.cs
new file mode 100644
index 000000000..ba2550e25
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/ImageGalleryControl.cs
@@ -0,0 +1,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();
+ }
+ }
+}