绑定到xpath时,Mediaelement repeatbehavior失败

Ken*_*enS 7 c# wpf mediaelement

我正在尝试使用MediaElement让视频永远重复.我在http://msdn.microsoft.com/en-us/library/ms741866.aspx上找到了以下代码,它运行正常.

<!-- The MediaElement control plays the sound. -->
        <MediaElement Name="myMediaElement" >
            <MediaElement.Triggers>
                <EventTrigger RoutedEvent="MediaElement.Loaded">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>

                                <!-- The MediaTimeline has a RepeatBehavior="Forever" which makes the media play
                 over and over indefinitely.-->
                                <MediaTimeline Source="C:\MyVideo1.wmv" Storyboard.TargetName="myMediaElement"  
                                                RepeatBehavior="Forever" />

                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </MediaElement.Triggers>
        </MediaElement>
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是当我尝试将MediaTimeLine绑定到xml源时,我收到错误 - "必须指定URI".

<MediaTimeline Source="{Binding XPath=MyVideos}" 
     Storyboard.TargetName="myMediaElement" RepeatBehavior="Forever" />
Run Code Online (Sandbox Code Playgroud)

是否有可以取代xaml的C#解决方案?

小智 1

为什么不使用值转换器?我知道它不完全是 WPF,即需要一些 C# 编码,但这似乎完全符合您的要求。WPF 教程有一个相当不错的解释,所以如果您不介意我向您推荐该页面,那么: http: //www.wpftutorial.net/ValueConverters.html