【问题标题】:Adding progresindicator to image downloading添加progreindicator到图像下载
【发布时间】:2014-05-03 18:11:28
【问题描述】:

我有应用程序页面,可以从街头摄像机查看。照片形式的相机大约每 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();
}

【问题讨论】:

标签: c# windows-phone-7


【解决方案1】:

对您的代码进行此更改:

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
猜你喜欢
  • 2011-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-03
  • 1970-01-01
  • 1970-01-01
  • 2019-09-13
  • 2017-07-12
相关资源
最近更新 更多