title: WPF ProgressBar & Dim Controls on Operation
body: <p>I'm looking to implement a progress bar (on my applications status bar) and at the same time dim all the MainWindow controls except minimize/maximize/close window buttons when I execution.</p>
  
  <p>Right now, I have a Progress Bar User Control with a Background worker process but it pops the progress bar control in a separate window. Here is the XAML for my status bar:</p>
  
  <pre><code>StatusBar x:Name="StatusB" Grid.Column="0" Grid.Row="5" Width="Auto" Height="30" Background="DarkGray" DockPanel.Dock="Bottom"&gt;
              &lt;StackPanel&gt;
                  &lt;Label Content="Status:" Foreground="White" Height="30" Width="50" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" &gt;&lt;/Label&gt;
              &lt;/StackPanel&gt;
              &lt;StackPanel&gt;
                  &lt;local:ProgressB&gt;&lt;/local:ProgressB&gt;
              &lt;/StackPanel&gt;
          &lt;/StatusBar&gt;
  </code></pre>
  
  <p>Here is my Progress Bar User Control:</p>
  
  <pre><code>&lt;Grid Width="250" Height="25"&gt;
      &lt;Label x:Name="lblProgress" Content="0%" Width="25" Height="20" Margin="155,2,70,0" Foreground="White" IsEnabled="False" Visibility="Hidden"&gt;&lt;/Label&gt;
      &lt;ProgressBar x:Name="progress" Height="20" IsIndeterminate="False" Width="151" HorizontalAlignment="Left" Margin="0,2,0,0"&gt;&lt;/ProgressBar&gt;
      &lt;Button x:Name="btnCancel" Width="50" Height="20" HorizontalAlignment="Right" Click="btnCancel_Click" Content="Cancel" Margin="0,2,0,0" IsEnabled="False" Visibility="Hidden"&gt;&lt;/Button&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>Background Worker:</p>
  
  <pre><code>        private void ExecuteBuild(object sender, ExecutedRoutedEventArgs e)
      {
          //Launching the bind/train process requires a separate proc
          ProcessStartInfo startInfo = new ProcessStartInfo("app.exe", filePath);
          startInfo.CreateNoWindow = true;
          startInfo.UseShellExecute = false;
          startInfo.WindowStyle = ProcessWindowStyle.Hidden;
          startInfo.RedirectStandardError = true;
          startInfo.RedirectStandardOutput = true;
  
          // Borrowed for build iterations (you need 3, minimum)
          int maxRecords = 3;
  
          pd = new ProgressB();
  
          // Cancel Build 
          pd.Cancel += CancelProcess;
  
          // Add multithread dispatcher
          System.Windows.Threading.Dispatcher pdDispatcher = pd.Dispatcher;
  
          //create our background worker and also have a cancel button
          worker = new BackgroundWorker();
          worker.WorkerSupportsCancellation = true;
  
          worker.DoWork += delegate(object s, DoWorkEventArgs args)
          {
              // Updates the progress text
              UpdateProgressDelegate update = new UpdateProgressDelegate(UpdateProgressText);
              int x = 0;
  
              for (x = 1; x &lt;= maxRecords; x++)
              {
                  if (worker.CancellationPending)
                  {
                      args.Cancel = true;
                      return;
                  }
  
                  System.Threading.Thread.Sleep(1);
  </code></pre>
  
  <p>When I have it pop a dialog window it works fine but when I put it in my status bar (see first XAML ref) it shows no progress whatsoever -- however the background process does work still. Any suggestions?</p>