C# 将progresindicator添加到图像下载

C# 将progresindicator添加到图像下载,c#,windows-phone-7,C#,Windows Phone 7,我有一个应用程序页面,可以从街边摄像机看到。照相/摄像机大约每30秒刷新一次。 我创建了一个用于刷新照片的按钮。 我想添加每次下载照片时都会显示的进度指示器。 我不知道如何以及在何处添加代码。 我尝试了许多例子,但都失败了。 因为我真的不知道如何打开和关闭它 public void downloading() { WebClient webClient = new WebClient(); webClient.OpenReadCompleted += new OpenRead

我有一个应用程序页面,可以从街边摄像机看到。照相/摄像机大约每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();
}

对代码进行以下更改:

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();
}

这可能会有帮助:谢谢,这是有效的,但是你在函数下载方面有一个小错误,应该是
IsVisible=true,
我有一个助手根据他从方法中得到的信息来设置这些值,所以我可能没有足够的精力把所有内容都写好:D