SL动态加载外部xap包
动态加载外部xap silverlight,通过映射和服务
View Code
private void button1_Click(object sender, RoutedEventArgs e) { //1 •使用WebClient下载SLRandarHitTest.xap文件,进行异步读取。 WebClient Appclient = new WebClient(); Appclient.OpenReadAsync(new Uri("SLRandarHitTest.xap", UriKind.Relative)); Appclient.OpenReadCompleted += new OpenReadCompletedEventHandler(Appclient_OpenReadCompleted); } void Appclient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { CreateXAPResource("SLRandar.dll","SLRandar.MainPage",e.Result); } /// <summary> /// 创建XAP包的反射实例并且加装到Canvas中 /// </summary> /// <param name="dllStr">XAP包中的编译完成的运行代码的DLL文件</param> /// <param name="mainStr">需要实例化的启动页面</param> /// <param name="resultStream">使用WebClient下载到的数据流</param> private void CreateXAPResource(string dllStr,string mainStr,Stream resultStream) { //2 • //3 •获取其他包提供的资源流信息 StreamResourceInfo streamResourceInfo = Application.GetResourceStream(new StreamResourceInfo(resultStream as Stream, null), new Uri(dllStr, UriKind.RelativeOrAbsolute)); //4 •对Stream进行反射 AssemblyPart assemblyPart = new AssemblyPart(); Assembly assembly = assemblyPart.Load(streamResourceInfo.Stream); //5 •(创建实例 var uc = (UserControl)assembly.CreateInstance(mainStr); lRoot.Children.Clear(); lRoot.Children.Add(uc); }
具体项目看:http://down.51cto.com/data/684492
或者其他3个
posted on 2013-02-20 11:06 YEKEYISHUO 阅读(323) 评论(1) 编辑 收藏 举报