title: Xamarin Forms Dynamically Load Content in a Page
body: <p>My current set up:</p>
  
  <p>Xamarin Forms, consisting of iOS, Android, WP app and shared PCL.
  Using MVVM Light to keep a nice separation of concerns.</p>
  
  <p>Brief intro into what I want to achieve.  I want to have a Base page that has a Cancel and Next button.  On pressing the Next button Content is loaded dynamically within that base page.</p>
  
  <p><strong>Xaml View:</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="LogInPresenterView"&gt;
    &lt;ContentPage.ToolbarItems&gt;
      &lt;ToolbarItem Text="Cancel" Priority="0" Order="Primary" Command="{Binding Cancel}"&gt;&lt;/ToolbarItem&gt;
      &lt;ToolbarItem Text="Next" Priority="1" Order="Primary" Command="{Binding Next}"&gt;&lt;/ToolbarItem&gt;
    &lt;/ContentPage.ToolbarItems&gt;
  &lt;/ContentPage&gt;
  </code></pre>
  
  <p><strong>ViewModel Code:</strong></p>
  
  <pre><code>public class LogInPresenterViewModel : ViewModelBase
      {
  
          public LogInPresenterViewModel() {}
  
          private RelayCommand _next;
          public RelayCommand Next
          {
              get
              {
                  return _next ?? (_next = new RelayCommand(async () =&gt; await DoNext()));
              }
          }
  
          private async Task DoNext()
          {
             // IN HERE I WOULD LIKE TO DYNCAMICALLY LOAD CONTENT / VIEWS
          }
  
      }
  </code></pre>
  
  <p>Usually you would have a StackLayout etc before the  element.  However, on clicking the Next Toolbar Item I want to dynamically load content (that has a viewmodel).</p>
  
  <p>So maybe my ICommand for my next button checked to see what the current content type was, and depending on that I would load another bit of content.</p>
  
  <p>The scenario would be, the base page would load along with the first bit of content - Enter Email and Password.  User enters that then clicks on next, if all ok, the content is replaced with the option to enter a security code, keeping the base Close and Next buttons at the top.</p>
  
  <p>Hopefully this makes sense.  I know what I want to do in my head, I just don't know how to translate that into Xamarin Forms...</p>