title: WPF - Notify ViewModel when object property is changed
body: <p>I'm new to WPF and MVVM (and programming in general), so sorry in advance for noobish question, but i really want to make this work in MVVM</p>
  
  <p>I have a ObservableCollection class and ViewModel where i use it, now i want to calculate OreMineTotal and OreTransportTotal in ViewModel every time when i change "Role" in my UI (two way binding). </p>
  
  <p>This works now but only when I add or remove item from ObservableCollection.</p>
  
  <p>1st queston
  Why is setter for Players ObservableCollection in ViewModel not firing when i change Player role in UI.</p>
  
  <p>2nd
  How to solve this in MVVM, i would like to know how to intercept/subscribe to RaisePropertyChanged("Role") that is in Player class from ViewModel</p>
  
  <p>In winforms i would handle it in (mouse click or whatever) event where i change player role, but i want to do it MVVM style</p>
  
  <pre><code>namespace MiningCalc.Model
  {
  public class Player : INotifyPropertyChanged
  {
  
      public Player()
      {
          items = new ObservableCollection&lt;MinedItems&gt;();
      }
      private string name;
      private string mass;
      private int fc;
      private int boost;
      private int log;
      private int role;
      private ObservableCollection&lt;MinedItems&gt; items;
  
      public ObservableCollection&lt;MinedItems&gt; Items
      {
          get
          {
              return items;
          }
          set
          {
              if (items != value)
              {
                  items = value;
                  RaisePropertyChanged("Items");
              }
          }
      }
  
      public string Name
      {
          get
          {
              return name;
          }
          set
          {
              if (name != value)
              {
                  name = value;
                  RaisePropertyChanged("Name");
              }
          }
      }
  
      ...... other variables .....
  
      public event PropertyChangedEventHandler PropertyChanged;
      void RaisePropertyChanged(string prop)
      {
          if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(prop)); }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And ViewModel</p>
  
  <pre><code>namespace MiningCalc.ViewModel
  {
  class ViewModelPlayer : INotifyPropertyChanged
  {
      private decimal oreMineTotal;
      private decimal oreTransportTotal;
      private ObservableCollection&lt;Player&gt; players;
  
      public ObservableCollection&lt;Player&gt; Players
      {
          get
          {
              return players;
          }
          set
          {
              players = value;
              OnPropertyChanged("Players");
              OnPropertyChanged("OreMineTotal"); //not working
              OnPropertyChanged("OreTransportTotal"); // not working
          }
      }
  
      public ViewModelPlayer()
      {
          players = new ObservableCollection&lt;Player&gt;();
          players.CollectionChanged += OnCollectionChanged;
          LoadLogCommand = new RelayCommand(LoadLog, LoadLog_CanExecute);
      }
  
      private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
      {
          //System.Windows.MessageBox.Show("Firing");
          OnPropertyChanged("OreMineTotal");
          OnPropertyChanged("OreTransportTotal");
      }
  
      public decimal OreMineTotal
      {
          get
          {
              oreMineTotal = Players.Where(x =&gt; x.Role == 0).Sum(a =&gt; decimal.Parse(a.Mass, NumberStyles.Any));
              return oreMineTotal;
          }
          set
          {
              oreMineTotal = value;
              OnPropertyChanged("OreMineTotal");
          }
      }
  
  
      public decimal OreTransportTotal
      {
          get
          {
              oreTransportTotal = Players.Where(x =&gt; x.Role == 1).Sum(a =&gt; decimal.Parse(a.Mass, NumberStyles.Any));
              return oreTransportTotal;
          }
          set
          {
              oreTransportTotal = value;
              OnPropertyChanged("OreTransportTotal");
          }
      }
      ...........
  </code></pre>