Silverlight 应用资源管理与导航技术解析
1. 按需下载程序集
在某些情况下,类库中的代码使用频率较低,或者某些用户根本不会使用。若类库包含大量代码或大型嵌入式资源(如图形),将其包含在应用程序中会增加 XAP 文件的大小,不必要地延长下载时间。此时,可以创建一个单独的组件程序集,仅在需要时下载。
操作步骤如下:
1. 确保依赖程序集不在 XAP 文件中:选择指向程序集的项目引用,在“属性”窗口中,将“复制本地”设置为 false。
2. 将程序集复制到网站的同一位置:如果使用 ASP.NET 测试网站,需将程序集添加到测试网站的 ClientBin 文件夹中。
以下是实现按需下载程序集的代码示例:
string uri = Application.Current.Host.Source.AbsoluteUri;
int index = uri.IndexOf("/ClientBin");
// In this example, the URI includes the /ClientBin portion, because we've
// decided to place the DLL in the ClientBin folder.
uri = uri.Substring(0, index) + "/ClientBin/ResourceClassLibrary.dll";
// Begin the download.
WebClient webClient = new WebClient ();
webClient.OpenReadCompleted += w
超级会员免费看
订阅专栏 解锁全文
30

被折叠的 条评论
为什么被折叠?



