title: Xamarin MVVM Light ViewModelLocator setting BindingContext in xaml
body: <p>I would like to set up BindingContext through xaml instead of back end code. Currently I am assigning like this:</p>
  
  <pre><code>public partial class MainPage : ContentPage
  {
      public MainPage()
      {
          InitializeComponent();
          BindingContext = App.Locator.Main;
      }
  }
  </code></pre>
  
  <p>How can I assing BindingContext via Xaml? I tried like this:</p>
  
  <p><strong>LoginPage.xaml</strong></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"
               x:Class="Codesign.DtpMobilePortable.Views.LoginPage" BindingContext="{Binding LoginPage, Source={StaticResource ViewModelLocator}}"&gt; 
    &lt;StackLayout Spacing="20" Padding="50" VerticalOptions="Center"&gt;
  
      &lt;Entry x:Name = "EntryUsername" Text="{Binding EntryUsernameText}" Placeholder = "Username"/&gt;  
      &lt;Entry x:Name = "EntryPassword" Text="{Binding EntryPasswordText}" Placeholder = "Password" IsPassword = "true"   /&gt;
  
      &lt;Button x:Name = "ButtonLogin"
                          Text = "{Binding LoginButtonText}"
                          TextColor = "White"
                          BackgroundColor = "{Binding LoginButtonColor}" Command="{Binding LoginCommand}"/&gt;    
    &lt;/StackLayout&gt;
  &lt;/ContentPage&gt;
  </code></pre>
  
  <p><strong>App.xaml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;Application xmlns="http://xamarin.com/schemas/2014/forms"
               xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
               xmlns:viewModels="clr-namespace:Codesign.DtpMobilePortable.ViewModels;assembly=Codesign.DtpMobilePortable"
               x:Class="Codesign.DtpMobilePortable.Views.App"&gt;
  &lt;Application.Resources&gt;
      &lt;viewModels:ViewModelLocator
          x:Key="ViewModelLocator" /&gt;
  &lt;/Application.Resources&gt;
  &lt;/Application&gt;
  </code></pre>
  
  <p>But I get error about StaticResource doesn't exist.</p>