2010-05-06 87 views
3

我有稱爲MyApp的Silverlight應用程序。在啓動過程中,MyApp使用以下代碼加載MyApp.Main.xap模塊:按需加載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)內部下載MyApp.Billing.xap,它也可以正常工作。可能是什麼問題?

回答

0

看看你是否有更多的成功,通過使用Application.Current.Host.Source的各種屬性來放置一個完整的(絕對)uri,而不是嘗試使用相對的一個(畢竟,它與它有什麼關係?)。