zoukankan
html css js c++ java
Silverlight3 加载其他xap
本文转载自:
http://www.pin5i.com/showtopic-26068.html
有些时候我们在设计有集成sl系统的时候总会想把xap作为基点来达到持续集成的效果。那么我们应该怎么做呢?
解决方法:
1.首先我们要用一个方法实现从源资中提取出Assembly:
1: Assembly LoadAssemblyFromXap(Stream packageStream, String assemblyName)
2: {
3: StreamResourceInfo resouceInfo = new StreamResourceInfo(packageStream, "application/binary");
4: Stream mainfestStream = Application.GetResourceStream(resouceInfo, new Uri("AppManifest.xaml", UriKind.Relative)).Stream;
5: String appManifestString = new StreamReader(mainfestStream).ReadToEnd();
6:
7: XElement deploymentRoot = XDocument.Parse(appManifestString).Root;
8: List<XElement> deploymentParts = (from assemblyParts in deploymentRoot.Elements().Elements() select assemblyParts).ToList();
9:
10: Assembly targetassembly = null;
11:
12: foreach (XElement xElement in deploymentParts)
13: {
14: String source = xElement.Attribute("Source").Value;
15: if (source == assemblyName)
16: {
17: StreamResourceInfo streamInfo = Application.GetResourceStream(resouceInfo, new Uri(source, UriKind.Relative));
18: AssemblyPart asmPart = new AssemblyPart();
19: targetassembly = asmPart.Load(streamInfo.Stream);
20: }
21: }
22: return targetassembly;
23: }
复制代码
2.利用一个webClient下载指定的其他xap文件,并在下载完成后,利用上边的方法把加载后的资料还完成一个UIElement,这样我们就可以使用了.
1: void MainPage_Loaded(object sender, RoutedEventArgs e)
2: {
3: //加一个xap文件所在的位置
4: Uri address = new Uri("http://localhost:4456/ClientBin/exproject.xap");
5: //实例一个webClient
6: WebClient webClient = new WebClient();
7: //注册一个下载完成事件
8: webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
9: //开始下载
10: webClient.OpenReadAsync(address);
11: }
复制代码
3.下载完成后通过LoadAssemblyFromXap方法还原xpa为UIElement:
1: void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
2: {
3: Stream stream = Application.GetResourceStream(
4: new StreamResourceInfo(e.Result, null),
5: new Uri("AppManifest.xaml", UriKind.Relative)).Stream;
6: String appManifestString = new StreamReader(stream).ReadToEnd();
7:
8: Assembly assembly = LoadAssemblyFromXap(e.Result, "exproject.dll");//other project name.dll
9: UIElement element = assembly.CreateInstance("exproject.MainPage") as UIElement;//other project name.mainPage
10: this.contaner.Children.Add(element);
11: }
复制代码
查看全文
相关阅读:
js中的单例模式
node.js
vscode设置
Array.from();Object.keys();Array.map()
js题
如何申请成为企业微信,并成为第三方服务商
微信企业号第三方平台应用开发
SQL Server 给表和字段添加说明
sql 语句写的行列转换
不同数据库之间复制表的数据的方法
原文地址:https://www.cnblogs.com/chenxizhang/p/1682288.html
最新文章
Linux开发环境搭建与使用系列教程
Linux网络编程——原始套接字实例:MAC 头部报文分析
Linux网络编程——原始套接字编程
elementUI table 懒加载,增删改数据动态更新
vue 父组件调用循环出来的子组件里的方法,怎么获取子组件index
技术人员白手起家,创业路。
从我的客户谈营销公司怎样将创业企业做大的
我是怎么通过技术白手起家创业 续2
我是怎么通过技术白手起家创业的。
推广Facebook技巧
热门文章
关于工信部批准发布138项通信行业标准等876项行业标准的公告
CRM认识的误区
Error occurred whiLe getting the data source contents for the report
为联合服务器代理角色配置计算机
中小企业项目的痛VS感人IT团队
es5中的for in 与es6中的for of的用法与区别
js深度复制三种方法
要解决的问题?
js中的观察者模式
js封装一个模块
Copyright © 2011-2022 走看看