title: Data Binding in MVVM WPF
body: <p>I have little knowledge in MVVM pattern. My problem is the data does not get binded to the xaml controls, no error is there. The progressbar is still at 0.</p>
  
  <p><strong>HomepageViewModel</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.ComponentModel;
  using CSMS_MVVM.Models;
  
  namespace CSMS_MVVM.ViewModels
  {
      class HomepageViewModel : INotifyPropertyChanged
      {
          BackgroundWorker _worker;
          public int _progress=20;
          public int Progress
          {
              get { return _progress; }
              set {
                  _progress = value;
                  OnPropertyChanged(new PropertyChangedEventArgs("Progress"));
              }
          }
          public void startBackgroundProcess()
          {
              _worker = new BackgroundWorker();
              _worker.DoWork += new DoWorkEventHandler(worker_DoWork);
              _worker.ProgressChanged += worker_Progress_Changed;
              _worker.RunWorkerAsync();
          }
  
          private void worker_Progress_Changed(object sender, ProgressChangedEventArgs e)
          {
              Progress = e.ProgressPercentage;
          }
  
          private void worker_DoWork(object sender, DoWorkEventArgs e)
          {
              Progress = 20;
          }
  
          #region INotifyPropertyChanged Members
  
          public event PropertyChangedEventHandler PropertyChanged;
          public void OnPropertyChanged(PropertyChangedEventArgs e)
          {
              if (PropertyChanged != null)
                  PropertyChanged(this, e);
          }
  
          #endregion
      }
  }
  </code></pre>
  
  <p><strong>Homepage.xaml.cs</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Timers;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Navigation;
  using System.Windows.Shapes;
  using CSMS_MVVM.ViewModels;
  
  namespace CSMS_MVVM.Views
  {
      /// &lt;summary&gt;
      /// Interaction logic for Homepage.xaml
      /// &lt;/summary&gt;
      public partial class Homepage : Page
      {
          HomepageViewModel hvm;
          public Homepage()
          {
              InitializeComponent();
          }
  
          private void Page_Loaded_1(object sender, RoutedEventArgs e)
          {
              hvm = new HomepageViewModel();
              hvm.startBackgroundProcess();
          }
      }
  }
  </code></pre>
  
  <p><strong>Homepage.xaml</strong></p>
  
  <pre><code>&lt;Page x:Class="CSMS_MVVM.Views.Homepage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:local="clr-namespace:CSMS_MVVM.ViewModels"
        mc:Ignorable="d" 
        d:DesignHeight="700" d:DesignWidth="1000"
      Title="Homepage" Loaded="Page_Loaded_1" Name="main"&gt;
  &lt;ProgressBar Name="pbStatus" Value="{Binding Path=Progress}" HorizontalAlignment="Center" Height="20" Margin="0,582,0,0" VerticalAlignment="Top" Width="300"&gt;
  -----
              &lt;ProgressBar.Effect&gt;
                  &lt;DropShadowEffect Color="#FFB6B6B6" ShadowDepth="3" BlurRadius="15" Direction="310"/&gt;
              &lt;/ProgressBar.Effect&gt;
          &lt;/ProgressBar&gt;
          &lt;TextBlock Text="{Binding Progress}" Margin="0,582,0,0" HorizontalAlignment="Center" VerticalAlignment="Top" /&gt;
          &lt;Label Content="Loading ..." HorizontalAlignment="Center" Margin="0,607,0,0" VerticalAlignment="Top"/&gt;
  ------
  &lt;/Page&gt;
  </code></pre>
  
  <p>Am i doing the correct coding? I searched the internet for an example but i did not understand them.</p>
  
  <p>Thanks!</p>