src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs
changeset 34 9e222810f5b5
parent 10 e8bfe1102e03
child 69 a4c44555f205
equal deleted inserted replaced
33:644464191714 34:9e222810f5b5
     5 using System.Windows.Controls;
     5 using System.Windows.Controls;
     6 using System.Windows.Data;
     6 using System.Windows.Data;
     7 using System.Windows.Media;
     7 using System.Windows.Media;
     8 using System.Windows.Media.Animation;
     8 using System.Windows.Media.Animation;
     9 using System.Windows.Navigation;
     9 using System.Windows.Navigation;
       
    10 using System.Windows.Controls.Primitives;
       
    11 using Microsoft.Surface.Presentation.Controls;
       
    12 using System.Windows.Threading;
    10 
    13 
    11 namespace FingersDance.Control.TimeLine
    14 namespace FingersDance.Control.TimeLine
    12 {
    15 {
    13 	public partial class UserControlTimeLine
    16 	public partial class UserControlTimeLine
    14 	{
    17     {
    15         public Microsoft.Surface.Presentation.Controls.SurfaceSlider Slider
    18 
       
    19         #region Variables
       
    20         private DispatcherTimer timer;
       
    21         private bool isDragging = false;
       
    22         private bool finishedDragging = false;
       
    23         #endregion
       
    24 
       
    25         public event EventHandler DragStarted;
       
    26         public event EventHandler DragCompleted;
       
    27         public event EventHandler TimerTick;
       
    28 
       
    29         #region Properties
       
    30 
       
    31         public SurfaceSlider Slider
    16         {
    32         {
    17             get {
    33             get
    18                 return SurfaceSlider;
    34             {
       
    35                 return slider;
    19             }
    36             }
    20             set {
    37             set
    21                 SurfaceSlider = value;
    38             {
       
    39                 slider = value;
    22             }
    40             }
    23         }
    41         }
       
    42         
       
    43         public bool IsDragging
       
    44         {
       
    45             get
       
    46             {
       
    47                 return isDragging;
       
    48             }
       
    49             set
       
    50             {
       
    51                 isDragging = value;
       
    52             }
       
    53         }
       
    54 
       
    55         public bool FinishedDragging
       
    56         {
       
    57             get
       
    58             {
       
    59                 return finishedDragging;
       
    60             }
       
    61             set
       
    62             {
       
    63                 finishedDragging = value;
       
    64             }
       
    65         }
       
    66 
       
    67         public DispatcherTimer Timer
       
    68         {
       
    69             get
       
    70             {
       
    71                 return timer;
       
    72             }
       
    73             set
       
    74             {
       
    75                 timer = value;
       
    76             }
       
    77         }
       
    78         #endregion
       
    79         
       
    80 
       
    81 
    24         
    82         
    25 		public UserControlTimeLine()
    83 		public UserControlTimeLine()
    26 		{
    84 		{
    27 			this.InitializeComponent();
    85 			this.InitializeComponent();
    28 
    86 
    29 			// Insert code required on object creation below this point.
    87 			// Insert code required on object creation below this point.
    30 		}
    88 		}
    31 
    89 
    32         private void SurfaceSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
    90         public void initslider(double totalmilliseconds)
    33         {
    91         {
    34             /*TimeSpan ts = TimeSpan.FromSeconds(e.NewValue);
    92             slider.Maximum = totalmilliseconds;
    35             LabelSliderPosition.Content =
       
    36                 String.Format("{0:00}:{1:00}:{2:00}",
       
    37                 ts.Hours, ts.Minutes, ts.Seconds);
       
    38             SurfaceSlider.Maximum = ts.TotalSeconds;
       
    39             SurfaceSlider.SmallChange = 1;
       
    40             SurfaceSlider.LargeChange = Math.Min(10, ts.Seconds / 10);*/
       
    41         }
    93         }
       
    94 
       
    95         #region Timer
       
    96         public void initTimer()
       
    97         {
       
    98             timer = new DispatcherTimer();
       
    99             timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
       
   100             timer.Tick += new EventHandler(timer_Tick);
       
   101         }
       
   102 
       
   103         public void timerStart()
       
   104         {
       
   105             if (timer != null)
       
   106                 timer.Start();
       
   107         }
       
   108         void timer_Tick(object sender, EventArgs e)
       
   109         {
       
   110             OnTimerTick();
       
   111             if (!isDragging)
       
   112             {
       
   113                 //slider.Value = media.Position.TotalMilliseconds;
       
   114             }
       
   115             if (finishedDragging)
       
   116             {
       
   117                 //int SliderValue = (int)slider.Value;
       
   118                 //TimeSpan ts = new TimeSpan(0, 0, 0, 0, SliderValue);
       
   119                // media.Position = ts;
       
   120                // media.Play();
       
   121                // isDragging = false;
       
   122                 //finishedDragging = false;
       
   123             }
       
   124         }
       
   125         protected virtual void OnTimerTick()
       
   126         {
       
   127             if (TimerTick != null)
       
   128                 TimerTick(this, new EventArgs());
       
   129         }
       
   130 
       
   131         #endregion
       
   132 
       
   133         private void sliderPosition_DragStarted(
       
   134             object sender, DragStartedEventArgs e)
       
   135         {
       
   136             isDragging = true;
       
   137             OnDragStarted();
       
   138            // media.Pause();
       
   139         }
       
   140         protected virtual void OnDragStarted()
       
   141         {
       
   142             if (DragStarted != null)
       
   143                 DragStarted(this, new EventArgs());
       
   144         }
       
   145 
       
   146         private void sliderPosition_DragCompleted(
       
   147             object sender, DragCompletedEventArgs e)
       
   148         {
       
   149             finishedDragging = true;
       
   150             OnDragCompleted();
       
   151         }
       
   152         protected virtual void OnDragCompleted()
       
   153         {
       
   154             if (DragCompleted != null)
       
   155                 DragCompleted(this, new EventArgs());
       
   156         }
       
   157 
    42 	}
   158 	}
    43 }
   159 }