0

I have a mediaelement in a WPF app. I'm trying to show the current position as a video plays in a label.

I have bound the Position to a label but it doesn't update when the video plays. It just shows 00:00:00.

How do I update the label with the current position as the video plays?

<MediaElement x:Name="ME" Grid.Column="1" />

<Label x:Name="lblTime" Content="{Binding Position, ElementName=ME}" />
James
  • 241
  • 3
  • 13
  • See this question and answer: [Binding a progressbar to a mediaelement in wpf](http://stackoverflow.com/questions/4058175/binding-a-progressbar-to-a-mediaelement-in-wpf). Note the usage of a timer to poll the MediaPosition property. –  May 14 '17 at 13:10

1 Answers1

1

The problem is that Position is not a dependancy property, therefore it doesn't notify the Property has changed. What you will need to do is implement a custom property in the code behind that will update on a timer:

Public TimeSpan MediaPosition
{
   get { return _mediaPosition; }
   set
   {
      _mediaPosition = value;
      PropertyChanged("MediaPosition");
   } 
}

The propertyChanged event will update the binding. You can read up on the propertyChanged event at:

https://msdn.microsoft.com/en-us/library/ms743695(v=vs.110).aspx

Ben Steele
  • 414
  • 2
  • 10