0

I have a class with public DownloadAsync Method inside, that downloads Content over Webclient. I create an Object of that class and call the download Method.

My problem is: I would like to block Elements on UI (e.g. Buttons) until the download is done. I could not find any solution so far.

One Idea is: I could call a MessageBox with message like "download is done" in the Downloadcomplete Method and to call somehow an Eventhandler for MessageBox. But how?

Any idea how to solve my problem?

EDIT: I know hot to disable Elements, but because of asynchronuous download in the download method, I don't know when the download is over in order to enable back the elements

Pamp
  • 69
  • 8

3 Answers3

1

add an event to your data class, and when the download has finished then trigger the event handler.

then in your page do something like this in your initialiser

  BusyMessage.Visibility = Visibility.Visible;
  this.DataContext = MYDownloaderClass.downloadedData;
  MyDownloaderClass.hasFinished += new EventHandler(hasFinished);

}

void hasFinished(object sender, EventArgs e){
  BusyMessage.Visibility = Visibility.Collapsed
}
Joseph Le Brech
  • 6,358
  • 11
  • 44
  • 80
  • thanky you! for people who search how to create an event hanlder: [http://stackoverflow.com/questions/5842339/how-to-trigger-event-when-a-variables-value-is-changed] – Pamp Dec 01 '11 at 16:54
0

You should just disable all the elements - set IsEnabled to false on buttons etc. If you want a quick and dirty solution - you can overlay the screen with a Rectangle, Border, Grid or Popup.

Filip Skakun
  • 31,347
  • 6
  • 71
  • 99
0

Try a busy indicator with an overlay. http://www.minddriven.de/index.php/technology/dot-net/windows-phone/wp7-xaml-viewmodel-busy-indicator

Derek Beattie
  • 9,189
  • 3
  • 28
  • 44
  • I have edited now my question, because my problem is: when should I activate back the controls? WebClient Calls DownloadAsyncCompleted Method, but I use an instance of the class, calling the public download Method, so there is no callback to the UI :\ – Pamp Dec 01 '11 at 13:22
  • Joseph's solution will work. If you're using mvvm, this http://baud.cz/blog/coproject-ria-caliburnmicro-demo-part-10 is a nice way to do busy. Separately, the with the async ctp you can make some of the callback business go away. – Derek Beattie Dec 01 '11 at 16:52