title: How to receive property changed notifications in a Form when a property changes in a class?
body: <p>I have a class with INotifyPropertyChanged interface. There is a property with the name Total Progress.</p>
  
  <p>I have a Form with Progress Bar on it. I want to send the TotalProgress property changed notifications to this Progress Bar and set it's value.</p>
  
  <p>Do I need to catch the PropertyChangedEvent in the Form also?</p>
  
  <p><strong>Edit: WPF Form Code</strong></p>
  
  <pre><code>using System.ComponentModel;
  using System.Windows;
  using System.Windows.Data;
  using System;
  using System.Windows.Threading;
  
  namespace SUpdater
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          BackgroundWorker bw = new BackgroundWorker();
          DownloadFile FileDownloadClass = new DownloadFile();
  
          public MainWindow()
          {
              InitializeComponent();
  
              bw.WorkerReportsProgress = true;
              bw.WorkerSupportsCancellation = true;
              bw.DoWork += new DoWorkEventHandler(bw_DoWork);
              bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
              bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
  
              progressBar1.SetBinding(System.Windows.Controls.ProgressBar.ValueProperty, new Binding("TotalPercentCompleted"));
              progressBar1.DataContext = FileDownloadClass;
  
              FileDownloadClass.PropertyChanged +=new PropertyChangedEventHandler(FileDownloadClass_PropertyChanged);
          }
  
          private void bw_DoWork(object sender, DoWorkEventArgs e)
          {
              FileDownloadClass.DownloadFiles();
  
              if ((bw.CancellationPending == true))
                  e.Cancel = true;
              else
              {
                  bw.ReportProgress(FileDownloadClass.TotalPercentCompleted);
              }
  
          }
  
          private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
          {
              if ((e.Cancelled == true))
              {
                  this.lblConnectionStatus.Content = " Download Canceled!";
              }
  
              else if (!(e.Error == null))
              {
                  this.lblConnectionStatus.Content = ("Error: " + e.Error.Message);
              }
  
              else
              {
                  this.lblConnectionStatus.Content = "Done!";
              }
          }
  
          private void FileDownloadClass_PropertyChanged(object sender, PropertyChangedEventArgs e)
          {
  
          }
  
          private void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
          {
              lblKbCompleted.Content = e.ProgressPercentage.ToString();
  
          }
  
          private void Window_Loaded(object sender, RoutedEventArgs e)
          {
              bw.RunWorkerAsync();
          }
  
      }
  }
  </code></pre>
  
  <p><strong>Edit: DownloadFile Class Code</strong></p>
  
  <pre><code>    sealed class DownloadFile:INotifyPropertyChanged
      {
  
          #region Private Fields
              // These fields hold the values for the public properties.
              private int progressBarValue = 0;
              private int totalKbCompleted = 0;
              private int totalBytesReceived = 0;
              private int remoteFileSize = 0;
  
              private string fileName = String.Empty;
              private string statusMessage = String.Empty;
          #endregion
  
              public event PropertyChangedEventHandler PropertyChanged;
  
              private void NotifyPropertyChanged(String info)
              {
                  if (PropertyChanged != null)
                  {
                      PropertyChanged(this, new PropertyChangedEventArgs(info));
                  }
              }
  
              #region Public Properties
              public int TotalKbCompleted
              {
                  get { return this.totalKbCompleted; }
  
                  set
                  {
                      if (value != this.totalKbCompleted)
                      {
                          this.totalKbCompleted = value/1024;
                          NotifyPropertyChanged("TotalKbCompleted");
                      }
                  }                
              }
  
              public int TotalBytesReceived
              {
                  get { return this.totalBytesReceived; }
  
                  set
                  {
                      if (value != this.totalBytesReceived)
                      {
                          this.totalBytesReceived = value;
                          NotifyPropertyChanged("TotalBytesReceived");
                      }
                  }
              }
  
              public int RemoteFileSize
              {
                  get { return this.remoteFileSize; }
  
                  set
                  {
                      if (value != this.remoteFileSize)
                      {
                          this.remoteFileSize = value;
                          NotifyPropertyChanged("RemoteFileSize");
                      }
                  }
              }
  
              public string CurrentFileName
              {
                  get { return this.fileName; }
  
                  set
                  {
                      if (value != this.fileName)
                      {
                          this.fileName = value;
                          NotifyPropertyChanged("CurrentFileName");
                      }
                  }
              }
  
              public string StatusMessage
              {
                  get { return this.statusMessage; }
  
                  set
                  {
                      if (value != this.statusMessage)
                      {
                          this.statusMessage = value;
                          NotifyPropertyChanged("StatusMessage");
                      }
                  }
              }
              #endregion
  
          public Int16 DownloadFiles()
          {
              try
              {
  
                  statusMessage = "Attempting Connection with Server";
  
                  DoEvents();
                  // create a new ftpclient object with the host and port number to use
                  FtpClient ftp = new FtpClient("mySite", 21);
  
                  // registered an event hook for the transfer complete event so we get an update when the transfer is over
                  //ftp.TransferComplete += new EventHandler&lt;TransferCompleteEventArgs&gt;(ftp_TransferComplete);
  
                  // open a connection to the ftp server with a username and password
                  statusMessage = "Connected. Authenticating ....";
                  ftp.Open("User Name", "Password");
  
                  // Determine File Size of the compressed file to download
                  statusMessage = "Getting File Details";
                  RemoteFileSize = Convert.ToInt32(ftp.GetFileSize("myFile.exe"));
  
                  ftp.TransferProgress += new EventHandler&lt;TransferProgressEventArgs&gt;(ftp_TransferProgress);
                  statusMessage = "Download from Server";
                  ftp.GetFile("myFile.exe", "E:\\Test\\myFile.exe", FileAction.Create);
  
                  // close the ftp connection
                  ftp.Close();
                  statusMessage = "Download Complete";
                  return 1;
              }
              catch (Exception ex)
              {
                  MessageBox.Show(ex.Message.ToString());
                  return 0;
              }
  
          }
  
  
          private void ftp_TransferProgress(object sender, TransferProgressEventArgs e)
          {
              totalBytesReceived = Convert.ToInt32(e.BytesTransferred.ToString());
              totalKbCompleted = Convert.ToInt32(totalKbCompleted + Convert.ToInt32(totalBytesReceived));
              progressBarValue = totalKbCompleted;
          }
  }
  </code></pre>