I did not use binding. I had a similar problem and I used a timer for this (my code is in Silverlight, suppose it will be the same in WPF):
The first direction (the film updates the slider)
private TimeSpan TotalTime;
private void MyMediaElement_MediaOpened(object sender, RoutedEventArgs e)
{
TotalTime = MyMediaElement.NaturalDuration.TimeSpan;
timerVideoTime = new DispatcherTimer();
timerVideoTime.Interval = TimeSpan.FromSeconds(1);
timerVideoTime.Tick += new EventHandler(timer_Tick);
timerVideoTime.Start();
}
void timer_Tick(object sender, EventArgs e)
{
if (MyMediaElement.NaturalDuration.TimeSpan.TotalSeconds > 0)
{
if (TotalTime.TotalSeconds > 0)
{
timeSlider.Value = MyMediaElement.Position.TotalSeconds /
TotalTime.TotalSeconds;
}
}
}
The second direction (the user updates the slider)
on the ctor form or something like this write the following line:
timeSlider.AddHandler(MouseLeftButtonUpEvent,
new MouseButtonEventHandler(timeSlider_MouseLeftButtonUp),
true);
and event handler:
private void timeSlider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (TotalTime.TotalSeconds > 0)
{
MyMediaElement.Position = TimeSpan.FromSeconds(timeSlider.Value * TotalTime.TotalSeconds);
}
}
source
share