xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF" Height="450" Width="300">
CurrentTimeInvalidated="Storyboard_Changed">
Storyboard.TargetName="meMediaElement"
RepeatBehavior="Forever" />
SourceName="sldPosition" >
SourceName="sldPosition" >
Margin="5" MinHeight="300" Stretch="Fill"
MediaOpened="MediaOpened" />
Name="sldPosition" Width="250"
ValueChanged="sldPosition_ValueChanged">
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace WpfApplication1
{
public partial class Window1 : Window
{
bool ignoreValueChanged = false;
public Window1()
{
InitializeComponent();
}
private void MediaOpened(object sender, EventArgs e)
{
sldPosition.Maximum = meMediaElement.NaturalDuration.TimeSpan.TotalMilliseconds;
}
private void Storyboard_Changed(object sender, EventArgs e)
{
ClockGroup clockGroup = sender as ClockGroup;
MediaClock mediaClock = clockGroup.Children[0] as MediaClock;
if (mediaClock.CurrentProgress.HasValue){
ignoreValueChanged = true;
sldPosition.Value = meMediaElement.Position.TotalMilliseconds;
ignoreValueChanged = false;
}
}
private void sldPosition_ValueChanged(object sender, RoutedPropertyChangedEventArgs e){
if (ignoreValueChanged)
{
return;
}
Storyboard.Seek(Panel,TimeSpan.FromMilliseconds(sldPosition.Value),TimeSeekOrigin.BeginTime);
}
}
}