Hello all!
I would like to draw a ProgressBar during the execution of my algorithms and display my map on the window.
I follow this tutorial : http://elegantcode.com/2011/10/07/ex...busyindicator/
But when my BackgroundWorker ended, my window is stille the same without my map...
However I don't understand because I use the dispatcher to change UI.
Below my code :
/// <summary> /// When the window is built /// </summary> /// <param name="sender">Fenêtre construite</param> /// <param name="e">Evènement</param> private void Window_Loaded(object sender, RoutedEventArgs r) { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (o, ea) => { //Take time Createur_Partie createur = new Createur_Partie(); createur.construirePartie(_joueurs, _grande); _partie = createur._monteur._partie; affichageMap(); }; worker.RunWorkerCompleted += (o, ea) => { busyIndicator.IsBusy = false; //On met à jour les informations sur les joueurs dans la partie de droite de la fenêtre //updateInfoJoueurs(); //On ajoute un observateur à notre partie // _partie.PropertyChanged += new PropertyChangedEventHandler(changement_partie); //_partie.debut(); }; worker.RunWorkerAsync(); } private void affichageMap() { Carte map = _partie._carte; for (int c = 0; c < map._largeur; c++) { Dispatcher.Invoke((Action)(() => mapGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(50, GridUnitType.Pixel) }))); } Console.WriteLine(10); for (int l = 0; l < map._hauteur; l++) { Dispatcher.Invoke((Action)(() => mapGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50, GridUnitType.Pixel) }))); for (int c = 0; c < map._largeur; c++) { Rectangle r = null; //On crée un rectangle pour case représentant les ressources r = createCase(c, l, map.getCase(c, l)); Dispatcher.Invoke((Action)(() => mapGrid.Children.Add(r))); //On crée une ellipse donnant une information rapide sur le nombre de troupes situé sur la case Dispatcher.Invoke((Action)(() => mapGrid.Children.Add(createEllipseUnite(c, l, r)))); foreach (Unite u in map.getCase(c, l).Unites) { Dispatcher.Invoke((Action)(() => mapGrid.Children.Add(affichageUnite(u, u.getType())))); } } } }
Thank you for advance