title: Xamarin Forms can't change variable value
body: <p>I want to make a simple Stopwatch app with xamarin forms. </p>
  
  <p>Here is the interface :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
               xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
               xmlns:local="clr-namespace:testvb"
               x:Class="testvb.MainPage"&gt;
      &lt;StackLayout&gt;
          &lt;Label Text="{Binding LabelText}"&gt;
              &lt;Label.BindingContext&gt;
                  &lt;local:GetDuration/&gt;
              &lt;/Label.BindingContext&gt;
              &lt;Label.GestureRecognizers&gt;
                  &lt;TapGestureRecognizer
                      Command="{Binding TapCommand}"&gt;
  
                  &lt;/TapGestureRecognizer&gt;
              &lt;/Label.GestureRecognizers&gt;
          &lt;/Label&gt;
          &lt;Label Text="{Binding SWDuration}"&gt;
              &lt;Label.BindingContext&gt;
                  &lt;local:GetDuration/&gt;
              &lt;/Label.BindingContext&gt;
          &lt;/Label&gt;
          &lt;Label Text="{Binding StartTimeText}"&gt;
              &lt;Label.BindingContext&gt;
                  &lt;local:GetDuration/&gt;
              &lt;/Label.BindingContext&gt;
          &lt;/Label&gt;
  
      &lt;/StackLayout&gt;
  
  &lt;/ContentPage&gt;
  </code></pre>
  
  <p>And the c#-class:</p>
  
  <pre><code>namespace testvb
  {
      class GetDuration : INotifyPropertyChanged
      {
          public event PropertyChangedEventHandler PropertyChanged;
          static string labeltext = "START";
          static string starttimetext = "Timer hasn't been started";
          ICommand tapCommand;
          static Stopwatch hstopwatch = new Stopwatch();
          string swduration;
          public GetDuration()
          {
              tapCommand = new Command(OnTapped);
  
              this.SWDuration = hstopwatch.Elapsed.ToString();
  
              Device.StartTimer(TimeSpan.FromSeconds(1), () =&gt;
              {
                  this.SWDuration = hstopwatch.Elapsed.ToString();
                 return true;
              });
  
          }
  
          public ICommand TapCommand
          {
              get
              {
                  return tapCommand;
              }
          }
  
          void OnTapped (object s)
          {
              if(LabelText == "START")
              {
                  LabelText = "STOP";
                  StartTimeText = DateTime.Now.ToString();
                  hstopwatch.Restart();
              }
              else
              {
                  LabelText = "START";
                  StartTimeText = "Timer has been stopped";
                  hstopwatch.Stop();
                  hstopwatch.Reset();
              }
          }
  
          public string LabelText
          {
              get
              {
                  return labeltext;
              }
              set
              {
                  if(labeltext != value)
                  {
                      labeltext = value;
                      if(PropertyChanged!=null)
                      {
                          PropertyChanged(this, new PropertyChangedEventArgs("LabelText"));                        
                      }
                  }
  
              }
          }
  
          public string SWDuration
          {
              get
              {
                  return swduration;
              }
              set
              {
                  if(swduration!=value)
                  {
                      swduration = value;
                      if(PropertyChanged!=null)
                      {
                          PropertyChanged(this, new PropertyChangedEventArgs("SWDuration"));
                      }
                  }
              }
          }
  
          public string StartTimeText
          {
              get
              {
                  return starttimetext;
              }
              set
              {
                  if (starttimetext != value)
                  {
                      starttimetext = value;
                      if (PropertyChanged != null)
                      {
                          PropertyChanged(this, new PropertyChangedEventArgs("StartTimeText"));
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>As from interface I have a label (toogle between start and stop when it is clicked), a label to show the duration, and a label to show the time when the stopwatch was started. </p>
  
  <p>The output on xamarin android simulator:_</p>
  
  <ul>
  <li>the label (start/stop) works well </li>
  <li>the duration can also be shown on the display BUT the last label won't change. </li>
  <li>Its value stays at "The timer hasn't been started"</li>
  </ul>
  
  <p>I don't understand why it can't work for the last label since the principal ist the same as the first label (start/stop). I would thank you if someone can point out where I misunderstand it or on which part I did wrong on my code. </p>
  
  <p>Thank you.</p>