问题
I have MediaElement and Slider. How I can bind MediaElement.Position to Slider.Value without DispatcherTimer?
回答1:
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
来源:https://stackoverflow.com/questions/11808108/binding-mediaelement-to-slider-position