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: }
复制代码
查看全文
相关阅读:
小程序样式表不支持级联选择器
小程序为什么脚本内不能使用window等对象
微信小程序怎么获取用户输入
php中不借助IDE快速定位行数或者方法定义的文件和位置
百度Ueditor编辑器取消多图上传对话框中的图片搜索
阿里云ECS购买优惠码
DEDE 5.7中各函数所在的文件和位置
自定义的parse_url逆向函数http_build_url,将数组转为url字符串
PHPMailer fe v4.11 For Thinkphp 3.2
javascript使用技巧总结,不断更新...
原文地址:https://www.cnblogs.com/chenxizhang/p/1682288.html
最新文章
C++面向对象高级编程(四)基础篇
C++面向对象高级编程(三)基础篇
C++面向对象高级编程(二)基础篇
C++面向对象高级编程(一)基础篇
C++11_Type Traits
service worker(二)之主页面与service worker通信
移动端Webapp中的那些Bug(转载)
module method
service worker(一)之离线应用
正则练习(一)
热门文章
传输密码加密方式
团队协作editconfig与eslint
vue自定义元素拖动
初识indexDB
使用fiddler对手机上的程序进行抓包(转载)
微信小程序(应用号)开发资源汇总整理
微信小程序(应用号)开发教程
小程序开发遇到问题如何联系微信官方
小程序本地资源无法通过 css 获取
如何修改窗口的背景色
Copyright © 2011-2022 走看看