src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs
changeset 34 9e222810f5b5
parent 10 e8bfe1102e03
child 69 a4c44555f205
--- a/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs	Fri Aug 07 01:03:14 2009 +0200
+++ b/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs	Sun Aug 09 18:29:41 2009 +0200
@@ -7,21 +7,79 @@
 using System.Windows.Media;
 using System.Windows.Media.Animation;
 using System.Windows.Navigation;
+using System.Windows.Controls.Primitives;
+using Microsoft.Surface.Presentation.Controls;
+using System.Windows.Threading;
 
 namespace FingersDance.Control.TimeLine
 {
 	public partial class UserControlTimeLine
-	{
-        public Microsoft.Surface.Presentation.Controls.SurfaceSlider Slider
+    {
+
+        #region Variables
+        private DispatcherTimer timer;
+        private bool isDragging = false;
+        private bool finishedDragging = false;
+        #endregion
+
+        public event EventHandler DragStarted;
+        public event EventHandler DragCompleted;
+        public event EventHandler TimerTick;
+
+        #region Properties
+
+        public SurfaceSlider Slider
         {
-            get {
-                return SurfaceSlider;
+            get
+            {
+                return slider;
             }
-            set {
-                SurfaceSlider = value;
+            set
+            {
+                slider = value;
             }
         }
         
+        public bool IsDragging
+        {
+            get
+            {
+                return isDragging;
+            }
+            set
+            {
+                isDragging = value;
+            }
+        }
+
+        public bool FinishedDragging
+        {
+            get
+            {
+                return finishedDragging;
+            }
+            set
+            {
+                finishedDragging = value;
+            }
+        }
+
+        public DispatcherTimer Timer
+        {
+            get
+            {
+                return timer;
+            }
+            set
+            {
+                timer = value;
+            }
+        }
+        #endregion
+        
+
+
+        
 		public UserControlTimeLine()
 		{
 			this.InitializeComponent();
@@ -29,15 +87,73 @@
 			// Insert code required on object creation below this point.
 		}
 
-        private void SurfaceSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
+        public void initslider(double totalmilliseconds)
+        {
+            slider.Maximum = totalmilliseconds;
+        }
+
+        #region Timer
+        public void initTimer()
+        {
+            timer = new DispatcherTimer();
+            timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
+            timer.Tick += new EventHandler(timer_Tick);
+        }
+
+        public void timerStart()
+        {
+            if (timer != null)
+                timer.Start();
+        }
+        void timer_Tick(object sender, EventArgs e)
         {
-            /*TimeSpan ts = TimeSpan.FromSeconds(e.NewValue);
-            LabelSliderPosition.Content =
-                String.Format("{0:00}:{1:00}:{2:00}",
-                ts.Hours, ts.Minutes, ts.Seconds);
-            SurfaceSlider.Maximum = ts.TotalSeconds;
-            SurfaceSlider.SmallChange = 1;
-            SurfaceSlider.LargeChange = Math.Min(10, ts.Seconds / 10);*/
+            OnTimerTick();
+            if (!isDragging)
+            {
+                //slider.Value = media.Position.TotalMilliseconds;
+            }
+            if (finishedDragging)
+            {
+                //int SliderValue = (int)slider.Value;
+                //TimeSpan ts = new TimeSpan(0, 0, 0, 0, SliderValue);
+               // media.Position = ts;
+               // media.Play();
+               // isDragging = false;
+                //finishedDragging = false;
+            }
+        }
+        protected virtual void OnTimerTick()
+        {
+            if (TimerTick != null)
+                TimerTick(this, new EventArgs());
         }
+
+        #endregion
+
+        private void sliderPosition_DragStarted(
+            object sender, DragStartedEventArgs e)
+        {
+            isDragging = true;
+            OnDragStarted();
+           // media.Pause();
+        }
+        protected virtual void OnDragStarted()
+        {
+            if (DragStarted != null)
+                DragStarted(this, new EventArgs());
+        }
+
+        private void sliderPosition_DragCompleted(
+            object sender, DragCompletedEventArgs e)
+        {
+            finishedDragging = true;
+            OnDragCompleted();
+        }
+        protected virtual void OnDragCompleted()
+        {
+            if (DragCompleted != null)
+                DragCompleted(this, new EventArgs());
+        }
+
 	}
 }
\ No newline at end of file