wpf 将 MediaElement 绑定到滑块位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11808108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Binding MediaElement to slider position
提问by user1524578
I have MediaElement and Slider. How I can bind MediaElement.Position to Slider.Value without DispatcherTimer?
我有 MediaElement 和 Slider。如何在没有 DispatcherTimer 的情况下将 MediaElement.Position 绑定到 Slider.Value?
回答by GameAlchemist
OK SO this COULDbe that :
OK所以这COULD是:
<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
所以你应该像微软在它的 MediaElement 小演示中做的那样:处理代码背后的一切。
http://msdn.microsoft.com/en-us/library/ms748248.aspx

