zoukankan      html  css  js  c++  java
  • Silverlight.WebClient下载

    System.Net.WebClient 是我们在客户端常用下载对象,image也是sl中出镜率较高的控件
    再加上一个MediaElement控件,让我们就此实现一个会动的silverlightLOGO吧~


    xaml的组成很简单:

    <UserControl x:Class="SilverlightApplication1.Page"
        xmlns
    ="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x
    ="http://schemas.microsoft.com/winfx/2006/xaml" 
        Width
    ="400" Height="300">
        
    <Canvas Background="White">
            
    <MediaElement Width="50" Height="50" AutoPlay="True" x:Name="myMp"/>
            
    <Image x:Name="myImage" Width="150" Height="50" Canvas.Left="60" ></Image>
        
    </Canvas>
    </UserControl>

    接下来我们将 Image绑定图片:
    new BitmapImage(new Uri("Properties/microsoft_silverlight_c - Copy.jpg", UriKind.Relative));

    随后声明WebClient对象和注册委托事件:
    webClient.openReadAsync()方法参数
    1.位于服务器上的数据源的路径.
    2.给与用户一个标识对本次访问服务器.

     WebClient wc = new WebClient();
     wc.OpenReadCompleted 
    += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
     wc.OpenReadAsync(
    new Uri("SilverlightLogo.zip", UriKind.Relative), "SilverlightLogo.wmv"); 

            
    void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
            
    {
                //读取数据完成

            }

    当下载数据完成后回调openreadcompleted方法
    我们可以从参数e中得到有用的数据

     String sURI = e.UserState as String;
     StreamResourceInfo zipResourceInfo 
    = new StreamResourceInfo(e.Result as Stream, null);
     StreamResourceInfo imageResourceInfo 
    = Application.GetResourceStream(zipResourceInfo, new Uri(sURI, UriKind.RelativeOrAbsolute));
     myMp.SetSource(imageResourceInfo.Stream);

    就这样我们已将一个会动的silverlightlogo展现给用户了,很简单吧~
    Source code: download.

  • 相关阅读:
    spring和设计模式
    Chrome插件下载网站图片
    MySql Illegal mix of collations 问题
    通过优化配置,提高MySql性能
    Windows下将Spring jar包部署为一个服务
    Apereo CAS增加登录方式。
    信息学竞赛C++基础教程
    关于codedecision和我本人
    信息学竞赛C++教程5.循环结构程序设计
    信息学竞赛C++教程3.分支结构程序设计
  • 原文地址:https://www.cnblogs.com/sonic1abc/p/1245338.html
Copyright © 2011-2022 走看看