我有应用程序页面从街道摄像机查看。照片形式相机每30秒刷新一次 我创建了一个用于刷新照片的按钮 我想添加进度指示器,每次下载照片时都会显示 我不知道如何以及在何处添加代码 我尝试过很多例子,但都失败了 因为我不太懂得如何打开和关闭它。
public void downloading()
{
WebClient webClient = new WebClient();
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(ImageOpenReadCompleted);
webClient.OpenReadAsync(new Uri("http://przeprawa.swi.pl/cgi-bin/kam.cgi?6&1399042906515&" + Guid.NewGuid()));
}
private void ImageOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (!e.Cancelled && e.Error == null)
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(e.Result);
image1.Source = bmp;
}
}
public void Refresh(object sender, EventArgs e)
{
downloading();
}
答案 0 :(得分:0)
对您的代码进行此更改:
public void downloading()
{
WebClient webClient = new WebClient();
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(ImageOpenReadCompleted);
webClient.OpenReadAsync(new Uri("http://przeprawa.swi.pl/cgi-bin/kam.cgi?6&1399042906515&" + Guid.NewGuid()));
var _progressIndicator = new ProgressIndicator
{
IsIndeterminate = true,
IsVisible = true,
Text = "Downloading...",
};
SystemTray.SetProgressIndicator(this, _progressIndicator);
}
private void ImageOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (!e.Cancelled && e.Error == null)
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(e.Result);
image1.Source = bmp;
var _progressIndicator = new ProgressIndicator
{
IsVisible = false,
};
SystemTray.SetProgressIndicator(this, _progressIndicator);
}
}
public void Refresh(object sender, EventArgs e)
{
downloading();
}