我正在使用进度条在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}" />
我想知道加载图片后进度条消失的最佳方法。
答案 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