知识大全 在silverlight中使用downloader

Posted 内容

篇首语:缥帙各舒散,前后互相逾。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 在silverlight中使用downloader相关的知识,希望对你有一定的参考价值。

  downloader对象为Silverlight 插件提供了下载功能 其通过HTTP(get)请求异步下载指定的内容

  downloader所支持的event包括

  Completed 下载完成 (Downloader)

  DownloadFailed 下载失败

  DownloadProgressChanged 下载进度变化 (Downloader)

  支持的方法包括

  Abort Equals FindName (DependencyObject) GetHost GetResponseText GetValue Open         Send SetValue

  下面这个DEMO演示使用downloader从网上下载jpg图片以及xaml文件并完成数据加载的过程

  

  

  其xaml代码如下所示          <Canvas  Canvas Left= >           <TextBlock Canvas Left= Canvas Top= Name= StartDownLoadImg >下载图片</TextBlock>           <TextBlock Canvas Left= Canvas Top= Name= StartDownLoadXaml >下载xaml</TextBlock>        </Canvas>        <! 下载进度条 >        <Canvas Canvas Top= >          <Rectangle Name= progressRectangle Canvas Left=   Height= Width=             Fill= Maroon />          <Rectangle Canvas Top = Canvas Left= Height=   Width=             StrokeThickness= Stroke= Black />          <TextBlock Name= progressText   Canvas Top = Canvas Left=             Text= % FontSize= />        </Canvas>        <Image Name= loadimg Height= Width= />        <Canvas Canvas Top= x:Name= loadxaml />

  接下来就是相应的js代码(详情见注释)          Silverlight_JsWeb Downloader = function()                        Silverlight_JsWeb Downloader prototype =                    handleLoad: function(plugIn userContext sender)                            this plugIn = plugIn;                // 附加事件处理程序                sender findName( StartDownLoadImg ) addEventListener( MouseLeftButtonDown                                Silverlight createDelegate(this this handleMouseLeftButtonDown));                sender findName( StartDownLoadXaml ) addEventListener( MouseLeftButtonDown                                Silverlight createDelegate(this this handleMouseLeftButtonDown));                progressText = sender findName( progressText );                progressRectangle = sender findName( progressRectangle );                        //开始下载            handleMouseLeftButtonDown:function (sender eventArgs)                            var slPlugin = sender getHost();                //创建downloader对象                var downloader = slPlugin createObject( downloader );                //下载进度变化事件绑定                downloader addEventListener( downloadProgressChanged                           Silverlight createDelegate(this this handleDownloadProgressChanged));                //下载结束事件绑定                downloader addEventListener( pleted                           Silverlight createDelegate(this this handleCompleted));                //下载失败事件绑定                downloader addEventListener( downloadFailed                           Silverlight createDelegate(this this handleDownloadFailed));                //初始化下载请求                if(sender name == StartDownLoadImg )                     downloader open( GET ClientBin/tang jpg );                                else                     downloader open( GET xaml/PathScene xaml );                                //downloader open( GET contoso TTF );字体下载

  //执行下载请求                downloader send();                        //下载进度改变            handleDownloadProgressChanged:function (sender eventArgs)                            var percentage = Math floor(sender downloadProgress * );                progressText text = percentage + % ;                progressRectangle width = percentage * ;                        //下载完成            handleCompleted:function (sender eventArgs)                            var plugin = sender getHost();                if (sender uri == ClientBin/tang jpg )                                    //绑定图片信息                    sender findName( loadimg ) setSource(sender );                    //清除 loadxaml 下的内容                    sender findName( loadxaml ) children clear();                    //var pathCanvas = sender findName( pathCanvas );                    //if (pathCanvas != null)                    //                    //    sender findName( loadxaml ) children remove(pathCanvas);                    //                    //sender findName( loadxaml ) children removeAt( );                                if (sender uri == xaml/PathScene xaml )                                    // 获取下载内容                     var xamlFragment = sender ResponseText;                    // 创建内容                     var xamlPath = ntent createFromXaml(xamlFragment);                    sender findName( loadxaml ) children add(xamlPath);                    // 清除图片绑定                    sender findName( loadimg ) Source = ;                                 // 下面为下载字体并进行加载的测试                  // var myTextBlock = sender findName( myTextBlock );                 //myTextBlock setFontSource(sender);                 // 设置字体 Contoso Font                  //myTextBlock fontFamily = Contoso Font ;                 //myTextBlock text = This is my new font! ;                        //下载失败处理事件            handleDownloadFailed:function (sender errorArgs)                            var errorMsg = Silverlight Error: \\n\\n ;                errorMsg += Error Type:    + errorArgs errorType + \\n ;                errorMsg += Error Message: + errorArgs errorMessage + \\n ;                errorMsg += Error Code:    + errorArgs errorCode + \\n ;                switch(errorArgs errorType)                                    case RuntimeError :                        if (errorArgs lineNumber != )                                                    errorMsg += Line: + errorArgs lineNumber + \\n ;                            errorMsg += Position: +  errorArgs charPosition + \\n ;                                                errorMsg += MethodName: + thodName + \\n ;                        break;                    case ParserError :                        errorMsg += Xaml File:      + errorArgs xamlFile      + \\n ;                        errorMsg += Xml Element:    + errorArgs xmlElement    + \\n ;                        errorMsg += Xml Attribute:  + errorArgs xmlAttribute  + \\n ;                        errorMsg += Line:           + errorArgs lineNumber    + \\n ;                        errorMsg += Position:       + errorArgs charPosition  + \\n ;                        break;                    default:                        break;                                alert(errorMsg);                   

        好了 今天的内容就到这里了 cha138/Article/program/net/201311/12957

相关参考

知识大全 Silverlight插件安装说明

Silverlight插件安装说明  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  Silverl

知识大全 使用silverlight中的Storyboard实现动画效果

使用silverlight中的Storyboard实现动画效果  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来

知识大全 Silverlight 中给TreeView添加复选框

Silverlight中给TreeView添加复选框  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

知识大全 如何配置支持Silverlight的Web服务器

如何配置支持Silverlight的Web服务器  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  

知识大全 应用程序Silverlight获取ASP.NET页面参数

应用程序Silverlight获取ASP.NET页面参数  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下

知识大全 Silverlight应用程序获取ASP.NET页面参数

Silverlight应用程序获取ASP.NET页面参数  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下

知识大全 虽非完美但却值得选择 Silverlight客观评测

虽非完美但却值得选择Silverlight客观评测  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 

知识大全 谈谈Silverlight 2中视觉状态管理第一部分

谈谈Silverlight2中视觉状态管理第一部分  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 

知识大全 新工具使Eclipse成为Silverlight IDE

新工具使Eclipse成为SilverlightIDE  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧

知识大全 三星s5660刷机后只能进入downloading界面了怎么办

三星s5660刷机后只能进入downloading界面了怎么办刷机步骤不对,或者方法有问题,或者固件包有问题刷机步骤:第一步:下载odin3.07程序第二步:准备好三星手机的刷机包,并解压。第三步:同