user1524578
user1524578

Reputation: 75

Binding MediaElement to slider position

I have MediaElement and Slider. How I can bind MediaElement.Position to Slider.Value without DispatcherTimer?

Upvotes: 3

Views: 7134

Answers (2)

Hans Voralberg
Hans Voralberg

Reputation: 69

Consider PositionChanged event is called periodically by the system just approximately 4 times per second.

So you can register for PositionChanged event and update value there from code behind.

Upvotes: 0

GameAlchemist
GameAlchemist

Reputation: 19294

OK SO this COULD be that :

<Slider 
    x:Name="PositionSlider"  
    Minimum="0" 
    Maximum="{Binding 
                  ElementName=mediaElement,  
                  Path=mediaElement.NaturalDuration.TimeSpan.TotalMilliseconds}"   
 />

<MediaElement 
    x:Name="mediaElement"
    Position="{Binding Value, 
               ElementName=PositionSlider, 
               Converter={StaticResource MyMsToTimeSpanConverter}}"  />

!! BUT !! Position is not a dependency property, so you cannot do any binding on it. When you say 'it doesn't work' ... SURE it doesn't, and it never will. binding requires dependency properties.

So you should do like Microsoft does for its MediaElement small demo : handle everything in code behind.
http://msdn.microsoft.com/en-us/library/ms748248.aspx

Upvotes: 1

Related Questions