微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Silverlight中大图片的加载进度

使用System.Media.Imaging.BitmapImage类的DownloadProgress事件,再配合ProgressBar等控件即可做出进度条效果,下面代码中就只简单的使用TextBlock显示进度

1、MainPage.xaml代码

1: <Grid x:Name="LayoutRoot" Background="White">
2: Image ="img"/>
3: TextBlock Text="正在加载 0%" ="TxtLoading" HorizontalAlignment="Center" Foreground="Black" VerticalAlignment="Center" 4: </Grid>

2、MainPage.xaml.cs代码

public partial class MainPage : UserControl
2: {
3: BitmapImage bitmapImage;
4: 
5: public MainPage()
6: {
7: InitializeComponent();
8: this.Loaded += new RoutedEventHandler(MainPage_Loaded);
9: }
10: 
11: private void MainPage_Loaded(object sender,RoutedEventArgs e)
12: {
13: bitmapImage = new BitmapImage();
14: img.source = bitmapImage;
15: bitmapImage.UriSource = new Uri("http://192.168.178.222/test.jpg");
16: img.Stretch = Stretch.Fill;
17: bitmapImage.DownloadProgress += new EventHandler<DownloadProgressEventArgs>(bitmapImage_DownloadProgress);
18: }
19: 
20: void bitmapImage_DownloadProgress(21: {
22: TxtLoading.Text = string.Format("正在加载 {0}%",e.Progress);
23: }
24: }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐