title: Implementing Progress bar using WPF with MVVM pattern (Using BackgroundWorker)
body: <h2>Note: This code works now. I have fixed some stupid mistake and I have also revised code as Steve Greatrex pointed out.</h2>
  
  <p>Original Posting LINK <a href="https://stackoverflow.com/questions/3520359/how-to-implement-a-progress-bar-using-the-mvvm-pattern/3520445#3520445">How to implement a progress bar using the MVVM pattern</a></p>
  
  <h2>ProgressbarSampleView.xaml</h2>
  
  <pre><code>  &lt;UserControl x:Class="MyProject.ProgressbarSampleView"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 Height="718" Width="1024"&gt;
  
    &lt;ProgressBar Grid.Row="1" 
                   Value="{Binding CurrentProgress, Mode=OneWay}" 
                   Visibility="{Binding ProgressVisibility}" 
                   Margin="22,0,25,0" /&gt;
  
    &lt;Button   Grid.Row="2"
              Content="Start Now"  
              Height="30" 
              Width="80" 
              HorizontalAlignment="Left" 
              Margin="22,4,0,0" 
              Name="btnStartNow" 
              VerticalAlignment="Top" 
              Command="{Binding Path=InstigateWorkCommand}" 
              /&gt;
    &lt;/UserControl&gt;
  </code></pre>
  
  <h2>ProggressbarSampleViewModel.cs</h2>
  
  <pre class="lang-cs prettyprint-override"><code>  namespace MyProject
    {
     public class ProggressbarSampleViewModel: ViewModelBase
     {
       private readonly BackgroundWorker worker; 
       private readonly ICommand instigateWorkCommand;
  
       public ProggressbarSampleViewModel()
       {
          this.instigateWorkCommand = new 
                        RelayCommand(o =&gt; this.worker.RunWorkerAsync(), o =&gt; !this.worker.IsBusy);
          this.worker = new BackgroundWorker();
          this.worker.DoWork += this.DoWork;
          this.worker.ProgressChanged += this.ProgressChanged;
      }
  
  
      public ICommand InstigateWorkCommand
      {
          get { return this.instigateWorkCommand; }
      }
  
      private int _currentProgress;
      public int CurrentProgress
      {
          get { return this._currentProgress; }
          private set
          {
              if (this._currentProgress != value)
              {
                  this._currentProgress = value;
                  OnPropertyChanged("CurrentProgress"); 
              }
          }
       }
  
       private void ProgressChanged(object sender, ProgressChangedEventArgs e)
       {
          this.CurrentProgress = e.ProgressPercentage;
       }
  
      private void DoWork(object sender, DoWorkEventArgs e)
      {
          // do time-consuming work here, calling ReportProgress as and when you can   
          for (int i = 0; i &lt; 100; i++)
          {
              Thread.Sleep(1000);
              _currentProgress = i;
              OnPropertyChanged("CurrentProgress");
          }
      }
  
    }
  </code></pre>