c# 4.0 - Show Splash Screen & Progress Bar with Percentage using MVVM & WPF -


i need show splash screen image & progress bar.

  1. in application start have code below show main window.

         splashscreenwindowviewmodel vm = new splashscreenwindowviewmodel();       autoresetevent ev = new autoresetevent(false);        thread uithread = new thread(() =>      {         vm.dispatcher = dispatcher.currentdispatcher;         ev.set();          dispatcher.currentdispatcher.begininvoke((action)delegate()         {             splashscreenwindow splashscreenwindow = new splashscreenwindow();             splashscreenwindow = new splashscreenwindow();             splashscreenwindow.show();             splashscreenwindow.datacontext = vm;             vm.instigateworkcommand.execute(null);          });          dispatcher.run();     });       uithread.setapartmentstate(apartmentstate.sta);       uithread.isbackground = true;       uithread.start();       ev.waitone(); 
  2. in main viewmodel have code below

    class mainviewmodel : viewmodelbase { rivate string _message; private object content; private readonly backgroundworker worker; private readonly icommand instigateworkcommand;

        public splashscreenwindowviewmodel()     {          this.instigateworkcommand = new          relaycommand(() => this.worker.runworkerasync(), () => !this.worker.isbusy);         this.worker = new backgroundworker { workerreportsprogress = true };                    this.worker.dowork += this.dowork;         this.worker.progresschanged += this.progresschanged;         _message = "0 % completed";      }        public icommand instigateworkcommand     {          { return this.instigateworkcommand; }     }      private double _currentprogress;     public double currentprogress             {         { return this._currentprogress; }         set         {             if (this._currentprogress != value)             {                  this._currentprogress = value;                                    raisepropertychanged("currentprogress");             }         }     }     private int _progressmax;     public int progressmax     {         { return this._progressmax; }          set         {             if(this._progressmax != value)             {               this._progressmax = value;               raisepropertychanged("progressmax");             }          }     }      private void progresschanged(object sender, progresschangedeventargs e)     {       this.currentprogress = e.progresspercentage;       }      private void dowork(object sender, doworkeventargs e)     {         // calling long running operation        dal.dotimeconsumingcode();        worker.reportprogress((int)e.argument);      }         public string message     {                 {             return _message;         }         set         {             if (message == value) return;             _message = value;             raisepropertychanged("message");         }     }       public object content     {                 {             return content;         }         set         {             if (content == value) return;             content = value;              raisepropertychanged("content");         }     }      public dispatcher dispatcher     {         get;         set;     } 

    }

    my ui has 1 user control progress bar , 1 splash main window. when long running operation completed , main window(main application) opened. //user control

            <progressbar height="27" value="{binding currentprogress, mode=oneway, updatesourcetrigger=propertychanged}"  margin="53,162,57,0" name="progressbar"  grid.row="1"              maximum="{binding path=progressmax, mode=oneway, updatesourcetrigger=propertychanged}"    visibility="{binding progressvisibility}"  /> 

    //splashwindow

      <localview:usercontrol/> 

my problem

progresschangedevent not firing , % completion not showing in text block either. please help

you have not registered complete handler , not calling progress properly. sample msdn covers all.

backgroundworker


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -