前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CaseStudy(showcase)数据篇-Loading的制作

CaseStudy(showcase)数据篇-Loading的制作

作者头像
用户1172164
发布2018-01-16 13:55:18
5760
发布2018-01-16 13:55:18
举报

做silvelight也有一段时间了,相册、游戏,刚刚完成的showcase这个小程序算是一个阶段了。这里就以showcase这个项目来做一下CaseStudy。

数据篇-Loading的制作

silverlight自带了一个loading。但是由于界面的需求可能需要定制化一下。这里我的思路是做两个sl文件用其中一个去加载另外一个。也就是说有两个xap文件一个是主要的也就是你做的silverlight程序文件,另一个小的是用来做loading的。

参考文章: 技巧:在Silverlight中如何访问外部xap文件中UserControl

代码语言:js
复制
public partial class Page : UserControl
     {
 public Page()
         {
             InitializeComponent();
             App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
             App.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);
 
 this.Init();
         }
 
 private void Init()
         {
             Uri address = new Uri(HtmlPage.Document.DocumentUri, "ClientBin/showcase.xap");
             WebClient webClient = new WebClient();
             webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
             webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);
             webClient.OpenReadAsync(address);
 
         }
 
 void webClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
         {
 //在这里实现你的loading动画
  double per = Convert.ToDouble(e.ProgressPercentage) / Convert.ToDouble(100);
             loadBar.Height = (App.Current.Host.Content.ActualHeight - 16) * per;
         }
 
 void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
         {
             Assembly assembly = LoadAssemblyFromXap(e.Result, "showcase.dll");
             UIElement element = assembly.CreateInstance("showcase.Page") as UIElement;
 this.LayoutRoot.Children.Clear();
 this.LayoutRoot.Children.Add(element);
         }
 
         Assembly LoadAssemblyFromXap(Stream packageStream, String assemblyName)
         {
             Stream stream = Application.GetResourceStream(
 new StreamResourceInfo(packageStream, null),
 new Uri("AppManifest.xaml", UriKind.Relative)).Stream;
 
             String appManifestString = new StreamReader(stream).ReadToEnd();
 
             Deployment deployment = (Deployment)XamlReader.Load(appManifestString);
 
             Assembly assembly = null;
 foreach (AssemblyPart assemblyPart in deployment.Parts)
             {
 if (assemblyPart.Source == assemblyName)
                 {
                     String source = assemblyPart.Source;
 
                     StreamResourceInfo streamInfo = Application.GetResourceStream(
 new StreamResourceInfo(packageStream,
 "application/binary"),
 new Uri(source, UriKind.Relative));
 
                     assembly = assemblyPart.Load(streamInfo.Stream);
 break;
                 }
             }
 return assembly;
         }
 
 
 void Content_FullScreenChanged(object sender, EventArgs e)
         {
 this.ResizeFrame();
         }
 
 void Content_Resized(object sender, EventArgs e)
         {
 this.ResizeFrame();
         }
 
 void ResizeFrame()
         {
             (this as UserControl).Width = App.Current.Host.Content.ActualWidth;
             (this as UserControl).Height = App.Current.Host.Content.ActualHeight;
         }
 
 void FullScreenMode()
         {
             App.Current.Host.Content.IsFullScreen = !App.Current.Host.Content.IsFullScreen;
 
         }
     }
 
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2008-07-22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 数据篇-Loading的制作
相关产品与服务
云开发 CloudBase
云开发(Tencent CloudBase,TCB)是腾讯云提供的云原生一体化开发环境和工具平台,为200万+企业和开发者提供高可用、自动弹性扩缩的后端云服务,可用于云端一体化开发多种端应用(小程序、公众号、Web 应用等),避免了应用开发过程中繁琐的服务器搭建及运维,开发者可以专注于业务逻辑的实现,开发门槛更低,效率更高。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档