title: how to access a control within Data Template from code behind?
body: <p>I have a <code>MediaElement</code> within the <code>DataTemplate</code> but I am unable to access it from the code behind.</p>
  
  <p>I am posting XAML code below:</p>
  
  <pre><code>&lt;Grid&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="605*"/&gt;
          &lt;ColumnDefinition Width="151*"/&gt;
      &lt;/Grid.ColumnDefinitions&gt;
      &lt;GroupBox Header="My Videos" Height="177" VerticalAlignment="Top" Margin="5,320,5,0" Grid.ColumnSpan="2"&gt;
          &lt;ListBox x:Name="VideoList" ItemsSource="{Binding Videos }" Width="auto" Height=" auto" Margin="0,0,0,0" Grid.ColumnSpan="2" &gt;
              &lt;DataTemplate x:Name="DTVideos"&gt;
                  &lt;ListBoxItem Name="lbivid1" BorderThickness="2"  Width="240" Selected="lbivid_Selected" &gt;
                      &lt;MediaElement Name="vidList" Height="150" Width="150" Source="{Binding SourceUri}" Position="00:00:05" LoadedBehavior="Pause" ScrubbingEnabled="True"/&gt;
                  &lt;/ListBoxItem&gt;
              &lt;/DataTemplate&gt;
              &lt;ItemsControl.ItemsPanel&gt;
                  &lt;ItemsPanelTemplate&gt;
                      &lt;StackPanel Orientation="Horizontal" Margin="0,0,0,0"/&gt;
                  &lt;/ItemsPanelTemplate&gt;
              &lt;/ItemsControl.ItemsPanel&gt;
          &lt;/ListBox&gt;
      &lt;/GroupBox&gt;     
      &lt;GroupBox Header="Preview" Height="320" Width="400" VerticalAlignment="Top" DockPanel.Dock="Left"&gt;
          &lt;MediaElement x:Name="videoPreview" HorizontalAlignment="Left" Height="300" VerticalAlignment="Top" Width="388"/&gt;
      &lt;/GroupBox&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>Code behind:</p>
  
  <pre><code> private void lbivid_Selected(object sender, RoutedEventArgs e)
   {   
      imagePreview.Visibility = Visibility.Hidden;   
      string urlStr = (VidList.Source).ToString();          
      Uri temp = new Uri(UrlStr);
      videoPreview.Source = temp;                         
   }   
  </code></pre>
  
  <p>Can anyone of you please tell me how can it be done?</p>