title: Current Time display with continuous display in WPF using MVVM
body: <p>I want to display current time on my screen with continuous updating in WPF screen using MVVM pattern.</p>
  
  <p>I am writing this code in my view model</p>
  
  <pre><code>// creating a property
  private string _currentDateTime;
  public string CurrentDateTime
  {
      get
      {
          return _currentDateTime;
      }
      set
      {
          if (value != _currentDateTime)
          {
              _currentDateTime = value;
              this.RaisePropertyChanged(() =&gt; this.CurrentDateTime);
          }
      }
  }
  </code></pre>
  
  <p>and I wrote this method </p>
  
  <pre><code> public string GetCurrentDateTime()
   {
       try
       {
           DispatcherTimer timer = new DispatcherTimer(new TimeSpan(0, 0, 1), 
               DispatcherPriority.Normal, 
               delegate
               {
                   this.CurrentDateTime = DateTime.Now.ToString("HH:mm:ss");
               },
               this.Dispatcher);
  
               return CurrentDateTime;
       }
       catch
       {
           return CurrentDateTime;
       }
  }
  </code></pre>
  
  <p>I binded my text block with property but it is showing exception as <code>this.CurrentDateTime</code> is <code>null</code>.</p>
  
  <p>Any suggestion why?</p>