title: MVVM - Binding custom object - trouble updating on UI
body: <p>I am using a custom class to keep track of the date in a game since DateTime doesn't allow for fictional setups. I have the class bound  to a <code>Label</code> in my window. Upon initialization, it displays fine, but refuses to update when I try to advance the date. In the following property located in the ViewModel, a messagebox confirms that the setter fires, but the value is deemed the same and <code>RaisePropertyChanged()</code> is never called:</p>
  
  <pre><code>public Date Date
  {
      get { return DataManager.Data.Date; }
      set
      {
          //Messagebox will display here...
          if (DataManager.Data.Date == value)
              return;
          //...But not here
          DataManager.Data.Date = value;
          RaisePropertyChanged(() =&gt; Date);
      }
  }
  </code></pre>
  
  <p>I've tried taking the if statement out but it still won't update.
  I have tried several ways of updating <code>Date</code> and none have worked. This is the only way I've been able to get the setter to fire at all (this is called in a command in the ViewModel):</p>
  
  <pre><code>Date = Date.AddDays(1);
  </code></pre>
  
  <p>Messageboxes confirm that this is updating the date properly (within the boxes, of course).</p>
  
  <p>Here is the <code>Date.cs</code> class in full:</p>
  
  <pre><code>public enum Season { Light, Shadow }
  public class Date : ObservableObject
  {
      #region Members
  
      private int _day;
  
      #endregion
  
      #region Properties
  
      public int Year
      {
          get { return _day / 100; }
      }
  
      public Season Season
      {
          get { return (DayOfYear &lt; 70) ? Season.Light : Season.Shadow; }
      }
  
      public int DayOfYear
      {
          get { return _day % 100; }
      }
  
      #endregion
  
      #region Construction
  
      public Date(int year, int day)
      {
          _day = (100 * year) + day;
      }
  
      #endregion
  
      #region Methods
  
      public Date AddDays(int value)
      {
          this._day += value;
  
          return this;
      }
  
      public override string ToString()
      {
          return string.Format("{0} {1}, {2}", DayOfYear, Season, Year);
      }
  
      #endregion
  }
  </code></pre>
  
  <p>Here's the XAML, maybe it will help. I have tried different binding options; none work.</p>
  
  <pre><code>&lt;Label Content="{Binding Date}"
             Grid.Row="1"
             Grid.Column="4"
             FontFamily="Pericles"
             FontSize="16"
             VerticalAlignment="Center"
             HorizontalAlignment="Right" /&gt;
  </code></pre>
  
  <p>At this point I don't know what to do to make <code>Date</code> update in the view. Any advice would be greatly appreciated.</p>
  
  <p><strong>Update:</strong> I should have mentioned that I'm using MVVM Light, which is where <code>ObservableObject</code> and <code>RaisePropertyChanged</code> come in. Also, my ViewModel inherits from MVVM Light's <code>ViewModelBase</code>. Other bound properties work without any problems.</p>
  
  <p><strong>Update:</strong> Per Sniffer's suggestion, <code>AddDays</code> now reads:</p>
  
  <pre><code>public Date AddDays(int value)
  {
      this._day += value;
  
      RaisePropertyChanged(() =&gt; Year);
      RaisePropertyChanged(() =&gt; Season);
      RaisePropertyChanged(() =&gt; DayOfYear);
  
      return this;
  }
  </code></pre>
  
  <p>The UI still doesn't update.</p>
  
  <p>When I call...</p>
  
  <pre><code>Date = Date.AddDays(1);
  RaisePropertyChanged(() =&gt; Date);
  System.Windows.MessageBox.Show(Date.ToString());
  </code></pre>
  
  <p>...inside the command, the Label doesn't change, but the MessageBox displays the updated date correctly.</p>
  
  <p><strong>Update + Possible Solution:</strong> I have managed to get things working.</p>
  
  <p>In the ViewModel:</p>
  
  <pre><code>public string Date
  {
      get { return DataManager.Data.Date.ToString(); }
  }
  </code></pre>
  
  <p>...and in the command</p>
  
  <pre><code>DataManager.Data.Date.AddDay(1);
  RaisePropertyChanged(() =&gt; Date);
  </code></pre>
  
  <p>In <code>Date.cs</code>:</p>
  
  <pre><code>public void AddDay(int value)
  {
      this._day += value;
  }
  </code></pre>
  
  <p>Raising properties isn't necessary with this method and <code>Date</code> doesn't even have to be observable. Given this information, if anybody could suggest improvements, I'm all ears. If not I'll call it a day with this.</p>