title: WPF ProgressBar with Value databinding
body: <p>I'm trying to databind the value property of a ProgressBar in WPF. I have a button set up to increment the databound int property for the Value of the ProgressBar. When I push the button it should make the ProgressBar's Value count up from 1 to 100. However... it doesn't seem to be working and I am not sure what I am doing wrong. Here is my XAML...</p>
  
  <pre><code>&lt;Window x:Class="ProgressBarExample2.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow" Height="250" Width="400" Background="WhiteSmoke"&gt;
  &lt;StackPanel VerticalAlignment="Center" HorizontalAlignment="Center"&gt;
      &lt;Button Name="goButton" Height="30" Width="50" Margin="0,10,0,50" Click="goButton_Click"&gt;GO!&lt;/Button&gt;
      &lt;ProgressBar Name="progressBar" Width="300" Height="30" Value="{Binding Percent, UpdateSourceTrigger=PropertyChanged}" /&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p></p>
  
  <p>and here is my code behind...</p>
  
  <pre><code>public partial class MainWindow : Window, INotifyPropertyChanged
  {
      #region INotifyPropertyChanged
  
      public event PropertyChangedEventHandler PropertyChanged;
      protected void NotifyPropertyChange(string propertyName)
      {
          if (PropertyChanged != null)
          {
              PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
          }
      }
  
      #endregion
  
      private int percent = 0;
      public int Percent
      {
          get { return this.percent; }
          set 
          {
              this.percent = value;
              NotifyPropertyChange("Percent");
          }
      }
  
      public MainWindow()
      {
          InitializeComponent();
      }
  
  
      private void goButton_Click(object sender, RoutedEventArgs e)
      {
          for (Percent = 0; Percent &lt;= 100; Percent++)
          {
              Thread.Sleep(50);
          }
      }
  }
  </code></pre>