Cannot reuse Mediaelement when binding to xpath

I am trying to get a video to repeat forever using MediaElement. I found the code below http://msdn.microsoft.com/en-us/library/ms741866.aspx and it works great.

<!-- 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> 

The problem I am facing is when I try to link MediaTimeLine to an xml source. I get an error - "Be sure to specify a URI."

 <MediaTimeline Source="{Binding XPath=MyVideos}" Storyboard.TargetName="myMediaElement" RepeatBehavior="Forever" /> 

Is there a C # solution that could replace xaml?

+7
c # wpf mediaelement
source share
1 answer

Why aren't you using a value converter? I know that this is not completely WPF, that is, some C # encoding is required, but this seems to do exactly what you need and need. The WPF Tutorials have a pretty decent explanation, so if you don't mind me linking to this page, then: http://www.wpftutorial.net/ValueConverters.html

+1
source share

All Articles