title: WinRT XAML Find control inside FlipView Item template
body: <p>So I have a flip view to display an article and in this flip view I have a Media Player from the <a href="http://playerframework.codeplex.com/" rel="nofollow">Microsoft Player Framework</a>. Now I want to be able to access this media player from code. </p>
  
  <p>However, every single example I have found has used FindName on the DataTemplate which WinRT doesn't seen to have.</p>
  
  <p>I have tried </p>
  
  <pre><code>var flipViewItem = this.flipView.ItemContainerGenerator.ContainerFromIndex(flipView.SelectedIndex);
  </code></pre>
  
  <p>and then using the VisualTreeHelper to find the Media Player but <code>flipViewItem</code> is always null.</p>
  
  <p>I tried data binding the video player - but this causes all videos in the flip view items to play simultaneously. </p>
  
  <p>Can someone please help?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>So this is my xaml that I am using:</p>
  
  <pre><code>&lt;FlipView
          x:Name="flipView"
          AutomationProperties.AutomationId="ItemsFlipView"
          AutomationProperties.Name="Item Details"
          TabIndex="1"
          Margin="0,127,0,10"
          ItemsSource="{Binding Source={StaticResource itemsViewSource}}" Grid.RowSpan="2"&gt;
  
          &lt;FlipView.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;UserControl Loaded="StartLayoutUpdates" Unloaded="StopLayoutUpdates"&gt;
                      &lt;ScrollViewer x:Name="scrollViewer" Style="{StaticResource HorizontalScrollViewerStyle}" Grid.Row="1"&gt;
  
                          &lt;common:RichTextColumns x:Name="richTextColumns" Margin="117,0,117,47"&gt;
                              &lt;RichTextBlock x:Name="richTextBlock" Width="560" Style="{StaticResource ItemRichTextStyle}"&gt;
                                  &lt;Paragraph&gt;
                                      &lt;Run FontSize="26.667" FontWeight="Light" Text="{Binding Title}"/&gt;
                                  &lt;/Paragraph&gt;
                                  &lt;Paragraph LineStackingStrategy="MaxHeight"&gt;
                                      &lt;InlineUIContainer&gt;
                                          &lt;Grid Width="560" Height="340" Margin="0,20,0,10"&gt;
                                              &lt;Grid.Background&gt;
                                                  &lt;ImageBrush ImageSource="{Binding Image}" Stretch="UniformToFill" /&gt;
                                              &lt;/Grid.Background&gt;
                                              &lt;Image x:Name="OverlayImage" Visibility="{Binding ShowVideo, Converter={StaticResource booleanToVisibilityConverter}}" Source="Assets/play-icon.png"/&gt;
                                              &lt;mmppf:MediaPlayer x:Name="ArticleVideo" Width="560" Height="340" /&gt;
                                          &lt;/Grid&gt;
                                      &lt;/InlineUIContainer&gt;
  </code></pre>
  
  <p>I have tried binding to the media player:</p>
  
  <pre><code>&lt;mmppf:MediaPlayer x:Name="ArticleVideo" Source="{Binding VideoPath}" Width="560" Height="340" PosterSource="{Binding Image}" AutoPlay="False" /&gt;
  </code></pre>
  
  <p>However, when I do that and set the videos to autoplay - they all autoplay. If I manually press play on the control, I receive a null reference exception at System.ComponentModel.PropertyChangedEventHandler.Invoke. The media player works fine outside the template.</p>
  
  <p>What is confusing, is that I know what I want to is possible. The SkyNews app for windows 8 does exactly what I want to do (add a video to a flip view item template). I had a look in c:\ProgramFiles\WindowsApps so see what their xaml looked like at it's the almost the same as mine - with no data binding on the media player. The only difference is that they have x:ConnectionId on the usercontrol and the grid containing the video player in the template. I don't know what x:ConnectionId does - but is it possible they are someone using that to access the controls from their code?</p>