10
|
1 |
using System; |
|
2 |
using System.IO; |
|
3 |
using System.Net; |
|
4 |
using System.Windows; |
|
5 |
using System.Windows.Controls; |
|
6 |
using System.Windows.Data; |
|
7 |
using System.Windows.Media; |
|
8 |
using System.Windows.Media.Animation; |
|
9 |
using System.Windows.Navigation; |
34
|
10 |
using System.Windows.Controls.Primitives; |
|
11 |
using Microsoft.Surface.Presentation.Controls; |
|
12 |
using System.Windows.Threading; |
10
|
13 |
|
|
14 |
namespace FingersDance.Control.TimeLine |
|
15 |
{ |
|
16 |
public partial class UserControlTimeLine |
34
|
17 |
{ |
|
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 |
10
|
32 |
{ |
34
|
33 |
get |
|
34 |
{ |
|
35 |
return slider; |
10
|
36 |
} |
34
|
37 |
set |
|
38 |
{ |
|
39 |
slider = value; |
10
|
40 |
} |
|
41 |
} |
|
42 |
|
34
|
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 |
|
|
82 |
|
10
|
83 |
public UserControlTimeLine() |
|
84 |
{ |
|
85 |
this.InitializeComponent(); |
|
86 |
|
|
87 |
// Insert code required on object creation below this point. |
|
88 |
} |
|
89 |
|
34
|
90 |
public void initslider(double totalmilliseconds) |
|
91 |
{ |
|
92 |
slider.Maximum = totalmilliseconds; |
|
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) |
10
|
109 |
{ |
34
|
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()); |
10
|
129 |
} |
34
|
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 |
|
10
|
158 |
} |
|
159 |
} |