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: }
复制代码
查看全文
相关阅读:
平衡二叉树
二叉树的深度
数字在升序数组中出现的次数
美国最受雇主欢迎的十大编程语言
重学数据结构(五、串)
重学数据结构(四、数组和广义表)
100个高频Spring面试题
重学数据结构(三、队列)
重学数据结构(二、栈)
Java学习之jackson篇
原文地址:https://www.cnblogs.com/chenxizhang/p/1682288.html
最新文章
docker容器数据卷
Docker之常用命令
docker系统化学习图文教程
docket镜像
docker系统化学习图文+视频教程
C++ 的两种换行符区别
【每日一题】21.边的染色 (DFS连通图 + 思维)
学习笔记:斜率优化DP
【每日一题】20.K-th Number (二分 + 尺取)
Codeforces Round #719 (Div. 3) A~E题解
热门文章
Educational Codeforces Round 108 (Rated for Div. 2) (A思维,Bmath,C前缀和,D枚举)
第十二届蓝桥杯C++B组 A~H题题解
【每日一题】18.华华给月月准备礼物 (水题,二分)
扑克牌顺子
CAS 算法与 Java 原子类
翻转单词顺序列
左旋转字符串
和为 S 的两个数字
和为 S 的连续正数序列
数组中只出现一次的数字
Copyright © 2011-2022 走看看