title: How to use progressBar in WPF
body: <p>I am trying to incorporate a progress bar in my main window after a button is pressed and the button is running its process. I know I am just missing something simple but I'm still new to WPF as I mainly use Windows Forms.</p>
  
  <p>My XML is structured as follows:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Window x:Class="Program1.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:local="clr-namespace:Program1"
          mc:Ignorable="d"
          Title="Program1" Height="1029" Width="1300" SnapsToDevicePixels="True" BorderThickness="0" Margin="0" ResizeMode="NoResize" Closing="Window_Closing"
          x:Name="FirstWindow"&gt;
      &lt;Grid x:Name="Grid1"&gt;
          &lt;Button x:Name="btnPopulate" Content="Populate" HorizontalAlignment="Left" Margin="243,66,0,0" VerticalAlignment="Top" Width="118" Height="29" Click="btnPopulate_Click"/&gt;
          &lt;Button x:Name="btnClear" Content="Clear" HorizontalAlignment="Left" Margin="366,66,0,0" VerticalAlignment="Top" Width="118" Height="29" Click="btnClear_Click"/&gt;
          &lt;ProgressBar x:Name="progressBar" HorizontalAlignment="Left" Height="30" Margin="10,943,0,0" VerticalAlignment="Top" Width="351"/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>I have my populate button click method as follows:</p>
  
  <pre><code>private void btnPopulate_Click(object sender, RoutedEventArgs e)
  {
      Thread backgroundThread = new Thread(
              new ThreadStart(() =&gt;
              {
                  for (int n = 0; n &lt; 100; n++)
                  {
                      Thread.Sleep(50);
                      progressBar.Value = n;
                  };
              }
          ));
      backgroundThread.Start();
  }
  </code></pre>
  
  <p>The issue I am facing is that I am getting this error:</p>
  
  <blockquote>
    <p>The name 'progressBar' does not exist in the current context</p>
  </blockquote>
  
  <p>and I am unsure how I can access the progressBar control from my button click method.</p>
  
  <p>I know I am likely missing something simple but I'm still trying to get the hang of WPF.</p>