使用System.Windows.Media.Imaging.BitmapImage類的DownloadProgress事件,再配合ProgressBar等控制項即可做出進度條效果,下面代碼中就只簡單的使用TextBlock顯示進度
1、MainPage.xaml代碼
1: <Grid x:Name="LayoutRoot" Background="White">
2: <Image x:Name="img"/>
3: <TextBlock Text="正在載入 0%" x:Name="TxtLoading" HorizontalAlignment="Center" Foreground="Black" VerticalAlignment="Center" />
4: </Grid>
2、MainPage.xaml.cs代碼
1: 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: private void bitmapImage_DownloadProgress(object sender, DownloadProgressEventArgs e)
21: {
22: TxtLoading.Text = string.Format("正在載入 {0}%", e.Progress);
23: }
24: }
創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()