title: Xamarin: Data Bindings not refreshing when used, but when some code is removed and typed back in it suddenly works
body: <p>I'm currently making an app in Xamarin. I created a list view which I'll be turning into a to-do list. I'm currently having a problem where if I use my [Add],[Remove], or [Edit] buttons on first launch, none of those options no matter what. To make it work, I have to remove the letter [s] from the [Tasks] then put it back in my code after a few seconds:</p>
  <pre><code>&lt;ListView x:Name=&quot;taskNames&quot; ItemsSource=&quot;{Binding Tasks}&quot; SelectedItem=&quot;{Binding SelectedTask}&quot;&gt;&lt;/ListView&gt;
  </code></pre>
  <p>I have no errors, warnings, or any of the like but this problem stumped me. Please watch the recording I did of it to fully understand what's happening: <a href="https://youtu.be/Y7UOjsucHpA" rel="nofollow noreferrer">https://youtu.be/Y7UOjsucHpA</a></p>
  <p>Here's my full ToDoPage.xaml code:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
  &lt;ContentPage xmlns=&quot;http://xamarin.com/schemas/2014/forms&quot;
               xmlns:x=&quot;http://schemas.microsoft.com/winfx/2009/xaml&quot; 
               xmlns:local=&quot;clr-namespace:Health.ViewModels&quot;
               x:Class=&quot;Health.Views.ToDoPage&quot;&gt;
  
      &lt;ContentPage.BindingContext&gt;
          &lt;local:ToDoListViewModel/&gt;
      &lt;/ContentPage.BindingContext&gt;
      
      &lt;ContentPage.Content&gt;
          &lt;StackLayout&gt;
              &lt;Label Text=&quot;To Do List&quot; FontSize=&quot;Title&quot; TextDecorations=&quot;Underline&quot;
                  VerticalOptions=&quot;CenterAndExpand&quot; 
                  HorizontalOptions=&quot;CenterAndExpand&quot; /&gt;
  
              &lt;Entry Placeholder=&quot;Tasks&quot; Text=&quot;{Binding TasksToAdd}&quot; HorizontalTextAlignment=&quot;Center&quot;&gt;&lt;/Entry&gt;
  
              &lt;Grid Grid.Row=&quot;1&quot; Grid.Column=&quot;3&quot; Padding=&quot;10,0,10,0&quot;&gt;
                  &lt;Button Text=&quot;Add&quot; Command=&quot;{Binding AddTasksCommand}&quot; WidthRequest=&quot;100&quot; HeightRequest=&quot;70&quot; HorizontalOptions=&quot;Start&quot;&gt;&lt;/Button&gt;
                  &lt;Button Text=&quot;Remove&quot; Command=&quot;{Binding RemoveTasksCommand}&quot; WidthRequest=&quot;100&quot; HeightRequest=&quot;70&quot; HorizontalOptions=&quot;Center&quot;&gt;&lt;/Button&gt;
                  &lt;Button Text=&quot;Edit&quot; Command=&quot;{Binding EditTasksCommand}&quot; WidthRequest=&quot;100&quot; HeightRequest=&quot;70&quot; HorizontalOptions=&quot;End&quot;&gt;&lt;/Button&gt;
              &lt;/Grid&gt;
              &lt;ListView x:Name=&quot;taskNames&quot; ItemsSource=&quot;{Binding Tasks}&quot; SelectedItem=&quot;{Binding SelectedTask}&quot;&gt;
              &lt;/ListView&gt;
          &lt;/StackLayout&gt;
      &lt;/ContentPage.Content&gt;
  &lt;/ContentPage&gt;
  </code></pre>
  <p>Then below, I have my ToDoListViewModel.cs code</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Collections.ObjectModel;
  using System.Linq;
  using System.Text;
  using System.Windows.Input;
  using Xamarin.Forms;
  
  namespace Health.ViewModels
  {
      class ToDoListViewModel
      {
          public ICommand AddTasksCommand =&gt; new Command(AddTask);
          public ICommand RemoveTasksCommand =&gt; new Command(RemoveTask);
          public ICommand EditTasksCommand =&gt; new Command(EditTask);
          public ObservableCollection&lt;string&gt; Tasks { get; set; } 
          public string TasksToAdd { get; set; }
  
          public string SelectedTask { get; set; }
  
          public ToDoListViewModel()
          {
              Tasks = new ObservableCollection&lt;string&gt;
              {
                  &quot;Task 1&quot;,
                  &quot;Task 2&quot;,
                  &quot;Task 3&quot;,
              };
          }
          public void AddTask()
          {
              Tasks.Add(TasksToAdd);
          }
  
          public void RemoveTask()
          {
              Tasks.Remove(SelectedTask);
          }
  
          public void EditTask()
          {
              int newIndex = Tasks.IndexOf(SelectedTask);
              Tasks.Remove(SelectedTask);
  
              Tasks.Add(TasksToAdd);
              int oldIndex = Tasks.IndexOf(TasksToAdd);
              
              Tasks.Move(oldIndex, newIndex);
          }
      }
  }
  </code></pre>
  <p>Then below is my ToDoPage.xaml.cs code</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  using Xamarin.Forms;
  using Xamarin.Forms.Xaml;
  
      namespace Health.Views
      {
          [XamlCompilation(XamlCompilationOptions.Compile)]
          public partial class ToDoPage : ContentPage
          {
              public ToDoPage()
              {
                  InitializeComponent();
                  taskNames.ItemsSource = new string[] { &quot;Task 1&quot;, &quot;Task 2&quot;, &quot;Task 3&quot; };
              }
          }
      }
  </code></pre>
  <p>Another thing I should add is that this ToDoPage.xaml is being referenced to my AppShell for navigating the app's tab bars. I'll have the code for it below too:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;Shell xmlns=&quot;http://xamarin.com/schemas/2014/forms&quot; 
         xmlns:x=&quot;http://schemas.microsoft.com/winfx/2009/xaml&quot; 
         xmlns:local=&quot;clr-namespace:Health.Views&quot; 
         xmlns:footer=&quot;clr-namespace:Health.ViewModels&quot;
         Title=&quot;Health&quot;
         x:Class=&quot;Health.AppShell&quot;&gt;
      &lt;Shell.Resources&gt;
          &lt;ResourceDictionary&gt;
              &lt;Style x:Key=&quot;BaseStyle&quot; TargetType=&quot;Element&quot;&gt;
                  &lt;Setter Property=&quot;Shell.BackgroundColor&quot; Value=&quot;{StaticResource Primary}&quot; /&gt;
                  &lt;Setter Property=&quot;Shell.ForegroundColor&quot; Value=&quot;White&quot; /&gt;
                  &lt;Setter Property=&quot;Shell.TitleColor&quot; Value=&quot;White&quot; /&gt;
                  &lt;Setter Property=&quot;Shell.DisabledColor&quot; Value=&quot;#B4FFFFFF&quot; /&gt;
                  &lt;Setter Property=&quot;Shell.UnselectedColor&quot; Value=&quot;#95FFFFFF&quot; /&gt;
                  &lt;Setter Property=&quot;Shell.TabBarBackgroundColor&quot; Value=&quot;{StaticResource Primary}&quot; /&gt;
                  &lt;Setter Property=&quot;Shell.TabBarForegroundColor&quot; Value=&quot;White&quot;/&gt;
                  &lt;Setter Property=&quot;Shell.TabBarUnselectedColor&quot; Value=&quot;#95FFFFFF&quot;/&gt;
                  &lt;Setter Property=&quot;Shell.TabBarTitleColor&quot; Value=&quot;White&quot;/&gt;
              &lt;/Style&gt;
              &lt;Style TargetType=&quot;TabBar&quot; BasedOn=&quot;{StaticResource BaseStyle}&quot; /&gt;
              &lt;Style TargetType=&quot;FlyoutItem&quot; BasedOn=&quot;{StaticResource BaseStyle}&quot; /&gt;
          &lt;/ResourceDictionary&gt;
      &lt;/Shell.Resources&gt;
      &lt;TabBar&gt;
          &lt;ShellContent Title=&quot;About&quot; Icon=&quot;icon_about.png&quot; Route=&quot;AboutPage&quot; ContentTemplate=&quot;{DataTemplate local:AboutPage}&quot; /&gt;
          &lt;ShellContent Title=&quot;To Do&quot; Icon=&quot;ToDoIcon.png&quot; Route=&quot;ToDoPage&quot; ContentTemplate=&quot;{DataTemplate local:ToDoPage}&quot;/&gt;
          &lt;ShellContent Title=&quot;Scheduler&quot; Icon=&quot;SchedulerIcon.png&quot; Route=&quot;SchedulerPage&quot; ContentTemplate=&quot;{DataTemplate local:SchedulerPage}&quot;/&gt;
          &lt;ShellContent Title=&quot;Exercise&quot; Icon=&quot;ExerciseIcon.png&quot; Route=&quot;ExercisePage&quot; ContentTemplate=&quot;{DataTemplate local:ExercisePage}&quot;/&gt;
      &lt;/TabBar&gt;
      &lt;TabBar&gt;
          &lt;ShellContent Route=&quot;LoginPage&quot; ContentTemplate=&quot;{DataTemplate local:LoginPage}&quot; /&gt;
      &lt;/TabBar&gt;
  &lt;/Shell&gt;
  </code></pre>
  <p>I'm really not sure why this is working, I hope someone can tell me what's happening because my code has no errors :/</p>