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.给与用户一个标识对本次访问服务器.
当下载数据完成后回调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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。