According to my testing, the relative source in xaml works when the video's property "Copy to Output Directory" is set to "Copy always".
I set the property "Copy to Output Directory" of the video w.wmv to "Copy always" and tested, it works.
Method 1:
<MediaElement Name="myMediaElement1" LoadedBehavior="Manual"
Source="Videos\w.wmv" IsHitTestVisible="True"
Margin="10">
</MediaElement>
Method 2:
<MediaElement Name="myMediaElement" LoadedBehavior="Manual"
IsHitTestVisible="True"
Margin="10">
</MediaElement>
Uri videoUri = new Uri("Videos/w.wmv", UriKind.RelativeOrAbsolute);
myMediaElement.Source = videoUri;
Method3: still not working
Uri videoUri = new Uri("pack://application:,,,/MediaElementSampleProject;component/Videos/w.wmv", UriKind.RelativeOrAbsolute);
myMediaElement.Source = videoUri;
You could use the previous two methods.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.