按需加载xap文件

时间:2010-05-06 06:30:14

标签: silverlight dynamically-loaded-xap

我有名为MyApp的Silverlight应用程序。在启动期间,MyApp使用以下代码加载MyApp.Main.xap模块:

WebClient wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(onMainModuleLoaded);
Uri uri = new Uri("MyApp.Main.xap", UriKind.Relative);
wc.OpenReadAsync(uri);

有效。在MyApp.Main中,我想加载另一个xap文件MyApp.Billing.xap,所以我的编写方式与上面相同

WebClient wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(onBillingModuleLoaded);
Uri uri = new Uri("MyApp.Billing.xap", UriKind.Relative);
wc.OpenReadAsync(uri);

但它会抛出一个错误,说找不到文件。 MyApp.Billing.xap文件位于ClientBin文件夹中,我可以通过浏览器中的绝对路径直接下载。如果我尝试不从MyApp.Main内部下载MyApp.Billing.xap,而是从MyApp内部(而不是MyAPp.Main.xap)下载,它也可以正常工作。可能是什么问题?

1 个答案:

答案 0 :(得分:0)

通过使用Application.Current.Host.Source处的各种属性来组合一个完整的(绝对)uri,而不是尝试使用相对的uri(毕竟,它相对于什么?),看看你是否取得了更大的成功。