加载图像时隐藏WP7进度条

时间:2012-12-19 21:09:17

标签: silverlight windows-phone-7 progress-bar

我正在使用进度条在Windows Phone 7的应用程序中加载图像。

bitmapImage.DownloadProgress += new EventHandler<DownloadProgressEventArgs (bitmapImage_DownloadProgress);

void bitmapImage_DownloadProgress(object sender, DownloadProgressEventArgs e)
{
   progressBar.Value = e.Progress;
}

XAML文件:

<ProgressBar x:Name="progressBar" IsIndeterminate="True" Width="300" Height="30" Style="{StaticResource PerformanceProgressBar}" />

我想知道加载图片后进度条消失的最佳方法。

2 个答案:

答案 0 :(得分:2)

使用在成功加载图片时触发的事件ImageOpened和在图片无法下载时触发​​的ImageFailed

bitmapImage.ImageOpened += new EventHandler<RoutedEventArgs>(bi_ImageOpened);
bitmapImage.ImageFailed += new EventHandler<ExceptionRoutedEventArgs>(bi_ImageFailed);

void bi_ImageFailed(object sender, ExceptionRoutedEventArgs e)
{
    MessageBox.Show("Download of image failed");
    progressBar.Visibility = Visibility.Collapsed;
}

void bi_ImageOpened(object sender, RoutedEventArgs e)
{
     progressBar.Visibility = Visibility.Collapsed;
}

答案 1 :(得分:1)

只需通过Visibility属性

隐藏它
progressBar.Visibility = Visibility.Collapsed