CaseStudy(showcase)数据篇-Loading的制作
做silvelight也有一段时间了,相册、游戏,刚刚完成的showcase这个小程序算是一个阶段了。这里就以showcase这个项目来做一下CaseStudy。
数据篇-Loading的制作
silverlight自带了一个loading。但是由于界面的需求可能需要定制化一下。这里我的思路是做两个sl文件用其中一个去加载另外一个。也就是说有两个xap文件一个是主要的也就是你做的silverlight程序文件,另一个小的是用来做loading的。
参考文章: 技巧:在Silverlight中如何访问外部xap文件中UserControl
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;
}
}
{
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;
}
}
作者:nasa
出处:nasa.cnblogs.com
联系:nasa_wz@hotmail.com
QQ:12446006
分类:
Silverlight
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构