title: Problem binding View to ViewModel with DataTemplate
body: <p>I have recently started trying to make sense of MVVM and am using the MvvmFoundation classes. I am attempting to use a DataTemplate for a View Model class to display the View. The XAML code is below: TVM is a property of type TrackViewModel.</p>
  
  <p>The TrackView placed in the Stack panel using a DataContext displays correctly. The content control version renders as an empty TrackViewModel.</p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;DataTemplate  DataType="{x:Type vm:TrackViewModel}" &gt;
          &lt;v:TrackView/&gt;
      &lt;/DataTemplate&gt;
  &lt;/Window.Resources&gt;
  &lt;StackPanel&gt;
      &lt;ContentControl Width="200" Height="50" Content="{Binding Path=TVM, UpdateSourceTrigger=PropertyChanged}"/&gt;
      &lt;v:TrackView DataContext="{Binding TVM}"/&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>It seems that I havent set up a link between the TrackView in the DataTemplate and the instansiated TrackViewModel, TVM. Consequently the PropertyChangedEventHandler's for TrackViewModel show up as null in the non-working case but are fine when I directly set the Datacontext.</p>
  
  <p>Any thoughts greatly appreciated.</p>
  
  <p>The TrackView XAML is as below:</p>
  
  <pre><code>&lt;UserControl.DataContext&gt;
      &lt;vm:TrackViewModel/&gt;
  &lt;/UserControl.DataContext&gt;
  
  &lt;UserControl.Resources&gt;
      &lt;LinearGradientBrush x:Key="barBackgroundBrush"  StartPoint="0,0" EndPoint="0,1" Opacity="0.7"&gt;
          &lt;GradientStop Offset="0" Color="Blue"/&gt;
          &lt;GradientStop Offset="0.3" Color="Aquamarine"/&gt;
          &lt;GradientStop Offset="1" Color="Blue"/&gt;
      &lt;/LinearGradientBrush&gt;
      &lt;LinearGradientBrush x:Key="barTrackingBrush"  StartPoint="0,0" EndPoint="0,1" Opacity="0.7"&gt;
          &lt;GradientStop Offset="0" Color="Orange"/&gt;
          &lt;GradientStop Offset="0.3" Color="OrangeRed"/&gt;
          &lt;GradientStop Offset="1" Color="Orange"/&gt;
  
      &lt;/LinearGradientBrush&gt;
  
      &lt;DataTemplate x:Key="RegionDataTemplate" &gt;
          &lt;Border CornerRadius="5" BorderThickness="3" Background="{StaticResource barTrackingBrush}" 
                      Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}"
                      Width="{Binding Path=Duration}"&gt;
              &lt;Border.RenderTransform&gt;
                  &lt;TranslateTransform X="{Binding Path=StartFrame}"/&gt;
              &lt;/Border.RenderTransform&gt;
          &lt;/Border&gt;
      &lt;/DataTemplate&gt;
         &lt;UserControl.DataContext&gt;
      &lt;vm:TrackViewModel/&gt;
  &lt;/UserControl.DataContext&gt;
  &lt;/UserControl.Resources&gt;
  
  &lt;StackPanel&gt;
      &lt;ItemsControl ItemsSource="{Binding Path=Regions, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" ItemTemplate="{StaticResource RegionDataTemplate}" VerticalAlignment="Center"&gt;
          &lt;ItemsControl.ItemsPanel&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;Canvas Background="{StaticResource barBackgroundBrush}" Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Panel}}}" VerticalAlignment="Stretch"/&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/ItemsControl.ItemsPanel&gt;
      &lt;/ItemsControl&gt;
  &lt;/StackPanel&gt;
  </code></pre>