Xaml Binding cannot see ViewModel in Template 10 app
<p>I'm using the latest Template 10 VS extension to create a UWP Windows 10 mobile app.
I've updated the template to use IOC (Autofac) so the ViewModels get resolved in the <code>app.xaml.cs</code> overridden <code>INavigable ResolveForPage(Page page, NavigationService)</code> method.
I've also updated the Page classes to each have a ViewModel property such as:</p>

<pre><code>public sealed partial class LoginPage : Page
{
    private LoginPageViewModel _viewModel;

    public LoginPageViewModel ViewModel =&gt; _viewModel ?? (_viewModel = (LoginPageViewModel)DataContext);

    public LoginPage()
    {
        InitializeComponent();
        NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;
    }
}
</code></pre>

<p>This has been fine until now as I've only used <code>x:Bind</code> in views and the binding to the viewmodel works. Since I installed the Template 10 validation package I've updated some views to use the older <code>Binding</code> method such as</p>

<pre><code>&lt;validate:ControlWrapper PropertyName="Password"&gt;
            &lt;TextBox x:Name="Password" 
                 HorizontalAlignment="Left"
                 Margin="10,220,0,0" 
                 TextWrapping="Wrap"
                 Text="{Binding ViewModel.LoginModel.Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                 VerticalAlignment="Top"
                 Width="{StaticResource FieldWidth}"
                 Height="60" 
                 PlaceholderText="Password" 
                 FontSize="24" 
                 InputScope="Password"&gt;
                &lt;Interactivity:Interaction.Behaviors&gt;
                    &lt;Core:EventTriggerBehavior&gt;
                        &lt;Behaviors:FocusAction /&gt;
                    &lt;/Core:EventTriggerBehavior&gt;
                &lt;/Interactivity:Interaction.Behaviors&gt;
            &lt;/TextBox&gt;
        &lt;/validate:ControlWrapper&gt;
</code></pre>

<p>This issue I have is that the text binding, <code>Text="{Binding ViewModel.LoginModel.Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"</code> doesn't work with the error <code>Cannot resolve symbol ViewModel due to unknown DataContext</code>.</p>

<p>As I'm new to UWP I think I'm missing some required configuration to ensure the DataContext is set to the correct ViewModel. I did try adding <code>DataContext = this</code> in the <code>app.xaml.cs</code> constructor but this didn't work.</p>

<p>Can anyone tell me which part of the puzzle I am missing?</p>