title: Understanding DataBinding in Windows Phone Develpment
body: <p>I'm having a little trouble understanding Data Binding.
  I am trying to learn <code>Windows Phone 8</code> Development.</p>
  
  <p>I am trying to understand some sample code here.</p>
  
  <p>In the <code>MainPage.xaml</code> he defines the <code>DataContext</code>:</p>
  
  <pre><code>&lt;phone:PhoneApplicationPage.DataContext&gt;
      &lt;Binding Path = "Master"
               Source="{StaticResource Locator}" /&gt;
  &lt;/phone:PhoneApplicationPage.DataContext&gt;
  </code></pre>
  
  <p><code>Locator</code> is a <code>ViewModelLocator</code> defined as <code>Resource</code> in <code>App.xaml</code>  and
  <code>Master</code> is a public property of type <code>MasterViewModel</code>.</p>
  
  <p>So I thought this means you have now access to the properties of the <code>MasterViewModel</code> class.
  And you have. But on the same page he binds to properties that are not in <code>MasterViewModel</code>, but in a totally different <code>ViewModel</code>:</p>
  
  <pre><code>Text="{Binding Model.FirstName}"
  </code></pre>
  
  <p><code>Model</code> is a property in a different <code>ViewModel</code>.</p>
  
  <p>So how can he access it? He did not overrde the <code>DataContext</code> somewhere as far as I can see.
  What am I missing?</p>
  
  <p>I didn't post a lot of code, because I think I just don't understand data binding yet and the answer will be obvious to you. I can show you more code if needed, it's sample code from Laurent Ibugnion.</p>
  
  <p>Thanks in advance</p>
  
  <p>EDIT:
  In his video he says he can use the dataBinding because in the DataTemplate the DataContext is set to a different ViewModel...but I can't see where he sets this viewModel:</p>
  
  <pre><code>&lt;phone:PhoneApplicationPage.Resources&gt;
      &lt;DataTemplate x:Key="FriendItemTemplate"&gt;
          &lt;Grid Width="480"
                Height="112"
                Margin="0"
                Background="#FF5E0000"&gt;
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width="124" /&gt;
                  &lt;ColumnDefinition /&gt;
              &lt;/Grid.ColumnDefinitions&gt;
  
              &lt;Rectangle Fill="#FF0B3100"
                         Stroke="Black"
                         Grid.ColumnSpan="2"
                         Visibility="{Binding OlderThanMeIndicatorVisibility, Mode=OneWay}" /&gt;
  
              &lt;Image Source="{Binding Model.PictureUri}"
                     VerticalAlignment="Top"
                     Margin="24,6,0,0" Height="100" /&gt;
  
              &lt;StackPanel Grid.Column="1"&gt;
                  &lt;StackPanel Orientation="Horizontal"
                              Margin="12,0,0,0"&gt;
                      &lt;TextBlock TextWrapping="Wrap"
                                 Text="{Binding Model.FirstName}"
                                 Style="{StaticResource PhoneTextGroupHeaderStyle}"
                                 Margin="0" /&gt;
  
                      &lt;TextBlock TextWrapping="Wrap"
                                 Text=" "
                                 Style="{StaticResource PhoneTextGroupHeaderStyle}"
                                 Margin="0" /&gt;
  
                      &lt;TextBlock TextWrapping="Wrap"
                                 Text="{Binding Model.LastName}"
                                 Style="{StaticResource PhoneTextGroupHeaderStyle}"
                                 Margin="0" /&gt;
                  &lt;/StackPanel&gt;
  
                  &lt;TextBlock TextWrapping="Wrap"
                             Text="{Binding Model.DateOfBirth}"
                             Style="{StaticResource PhoneTextLargeStyle}" /&gt;
              &lt;/StackPanel&gt;
          &lt;/Grid&gt;
      &lt;/DataTemplate&gt;
  &lt;/phone:PhoneApplicationPage.Resources&gt;
  </code></pre>
  
  <p>EDIT: SOLVED
  i finally found it, </p>
  
  <pre><code>ListBox ItemsSource="{Binding Friends}"
                       ItemTemplate="{StaticResource FriendItemTemplate}" SelectedItem="{Binding SelectedFriend, Mode=TwoWay}" /&gt;
  </code></pre>
  
  <p>Thanks for your help</p>