Silverlight 2.0 Beta 1 is inconsistent with Uri Relative.

Problem:

In designing phase when you give URI relative address to MediaElement/Image or set any source from the code behind, the relative address is with the xaml/vb/cs file you are defining it in, for example, consider the following project

2008-03-06_165455

In Page.xaml if you define the source, the preview shows the image, but when the application is run it doesn't show the image

<Image x:Name="bg" Source="bg.jpg"/>

Reason:

The reason is the relative uri for the source, however the preview works but when complied the "xap" is generated in ClientBin directory, and the relative Uri will be changed to ClientBin so in run time it will look for the bg.jpg in ClientBin directory.

Solution:

Solution 1: Solution is the provide absolute Uri for the source, eg.,

<Image x:Name="bg" Source="http://website.com/bg.jpg"/>

Solution 2: Copy all your assets in ClientBin directory

Solution 3: Use absolute uri if setting from code behind eg.,

<MediaElement x:Name="ThisVideo" Height="500" />

Now set the source from code behind using Application path, in VB (take out _  and add ; at the end for C#),

VideoScreen.Source = _
 New Uri(Application.Current.Host.Source.AbsolutePath & _ 
"../../../video.wmv", UriKind.Absolute)

Please leave your comments.