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.

  • 相关阅读:
    chmod: changing permissions of ‘/etc/fstab': Read-only file system
    让Mac终端保持(SSH)与远程的连接状态
    修改数据库密码
    SSH密钥登录让Linux VPS/服务器更安全
    redis 使用redis Desktop manger进行远程进行链接
    mysql 性能
    对阿里云服务器(数据盘已分区并格式化)的数据盘进行扩容
    备份数据库的shell
    window上可以执行的shell脚本,复制到linux上执行报错了
    自然语言处理中的N-Gram模型
  • 原文地址:https://www.cnblogs.com/sonic1abc/p/1245338.html
Copyright © 2011-2022 走看看