我的Silverlight项目的目录结构是这样的:的Silverlight:下载本地文件与Web客户端
\Bin
- MainModule.xap
- \Images
--- Image1.png
--- Image2.png
- \Modules
--- SubModule.xap
我希望能够通过任何Web服务器或通过Visual Studio直接运行(调试目的我想绕过内容下载)。
在我的媒体加载代码我这样做如下:
if (runningLocally)
{
var bitmapImage = new BitmapImage();
bitmapImage.UriSource = new Uri("Images/Image1.png", UriKind.Relative);
var image = new Image();
image.Source = bitmapImage;
}
else
{
WebClient wc = new WebClient();
wc.OpenReadCompleted += (s, e) =>
{
var bitmapImage = new BitmapImage();
bitmapImage.SetSource(e.Result);
var image = new Image();
image.Source = bitmapImage;
};
wc.OpenReadAsync(new Uri("Images/Image1.png", UriKind.Relative));
}
这适用于图像,但我也有子模块,其只是组件住房UserControl
秒。由于Silverlight无法读取磁盘,因此我已经辞职了,因为我将不得不“下载”XAP,因为我需要的是否是本地运行的。问题是,如果我在本地运行该项目,并尝试使用WebClient
下载XAP我得到一个异常:
System.Net.WebException: An exception occurred during a WebClient request. ---> System.NotSupportedException: The URI prefix is not recognized.
有没有运行时,我可以让我的子模块XAPs任何方式(Web客户端或其他方式)直接Silverlight项目而不是击中Web服务器?
编辑:
忘了提我使用MEF与DeploymentCatalog
也试过,虽然我没有得到一个例外,从来都没有撰写所以我只能假定它有同样的问题。