downloader對象為Silverlight 插件提供了下載功能
downloader所支持的event包括
Completed
DownloadFailed
DownloadProgressChanged
支持的方法包括
Abort
Send
下面這個DEMO演示使用downloader從網上下載jpg圖片以及xaml文件並完成數據加載的過程
其xaml代碼如下所示
<TextBlock Canvas
<TextBlock Canvas
</Canvas>
<!
<Canvas Canvas
<Rectangle Name=
Fill=
<Rectangle Canvas
StrokeThickness=
<TextBlock Name=
Text=
</Canvas>
<Image Name=
<Canvas Canvas
接下來就是相應的js代碼(詳情見注釋)
{
}
Silverlight_JsWeb
{
handleLoad: function(plugIn
{
this
// 附加事件處理程序
sender
Silverlight
sender
Silverlight
progressText = sender
progressRectangle = sender
}
//開始下載
handleMouseLeftButtonDown:function (sender
{
var slPlugin = sender
//創建downloader對象
var downloader = slPlugin
//下載進度變化事件綁定
downloader
Silverlight
//下載結束事件綁定
downloader
Silverlight
//下載失敗事件綁定
downloader
Silverlight
//初始化下載請求
if(sender
downloader
}
else {
downloader
}
//downloader
//執行下載請求
downloader
}
//下載進度改變
handleDownloadProgressChanged:function (sender
{
var percentage = Math
progressText
progressRectangle
}
//下載完成
handleCompleted:function (sender
{
var plugin = sender
if (sender
{
//綁定圖片信息
sender
//清除 loadxaml 下的內容
sender
//var pathCanvas = sender
//if (pathCanvas != null)
//{
// sender
//}
//sender
}
if (sender
{
// 獲取下載內容
var xamlFragment = sender
// 創建內容
var xamlPath = ntent
sender
// 清除圖片綁定
sender
}
// 下面為下載字體並進行加載的測試
// var myTextBlock = sender
//myTextBlock
// 設置字體
//myTextBlock
//myTextBlock
}
//下載失敗處理事件
handleDownloadFailed:function (sender
{
var errorMsg =
errorMsg +=
errorMsg +=
errorMsg +=
switch(errorArgs
{
case
if (errorArgs
{
errorMsg +=
errorMsg +=
}
errorMsg +=
break;
case
errorMsg +=
errorMsg +=
errorMsg +=
errorMsg +=
errorMsg +=
break;
default:
break;
}
alert(errorMsg);
}
}
好了
From:http://tw.wingwit.com/Article/program/net/201311/12957.html