使用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: }