title: Populate ListView when page is loaded (Xamarin.Forms) using a Command
body: <p>I have tried unsuccessfully to populate a ListView bound to an ObservableCollection when a page is loaded. Currently I have it working with a button (bound to a Command) with the following code.</p>
  
  <p>View:</p>
  
  <pre><code>&lt;Button Text="Load Items" Command="{Binding LoadItemsCommand}"&gt;&lt;/Button&gt;
  &lt;ActivityIndicator IsRunning="{Binding IsBusy}" IsVisible="{Binding IsBusy}" /&gt;
  &lt;ScrollView&gt;
    &lt;ListView ItemsSource="{Binding Items}"&gt;      
      .....
    &lt;/ListView&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>View.cs:</p>
  
  <pre><code>private ItemsViewModel _itemsViewModel;
  
  public ItemsView()
  {
      InitializeComponent();
      _itemsViewModel = new ItemsViewModel();
      BindingContext = _itemsViewModel;
  }
  </code></pre>
  
  <p>ViewModel:</p>
  
  <pre><code>public ObservableCollection&lt;Item&gt; Items{ get; set; }
  public Command LoadItemsCommand { get; set; }
  
  public ItemsViewModel()
  {
      Items = new ObservableCollection&lt;Item&gt;();
      _isBusy = false;
  
      LoadItemsCommand = new Command(async () =&gt; await LoadItems(), () =&gt; !IsBusy);    
  }
  
  public async Task LoadItems()
  {
      if (!IsBusy)
      {
          IsBusy = true;
          await Task.Delay(3000); 
          var loadedItems = ItemsService.LoadItemsDirectory(); 
  
          foreach (var item in loadedItems)
              Items.Add(item);
  
          IsBusy = false;
      }
  }
  </code></pre>
  
  <p>This works perfectly with the button but I have no idea how to do it automatically. I tried binding the RefreshCommand property of the listview to my command but nothing.</p>