how to access a control within Data Template from code behind?

You should be able to access your control using the FrameworkTemplate.FindName method... first, get the ContentPresenter from one of the ListBoxItems:

ContentPresenter contentPresenter = FindVisualChild<ContentPresenter>(yourListBoxItem);

Then get the DataTemplate from the ContentPresenter:

DataTemplate yourDataTemplate = contentPresenter.ContentTemplate;

Then get the MediaElement from the DataTemplate:

MediaElement yourMediaElement = yourDataTemplate.FindName("vidList", contentPresenter) 
as MediaElement;
if (yourMediaElement != null)
{
    // Do something with yourMediaElement here
}

Please see the FrameworkTemplate.FindName Method page on MSDN for more information.

Tags:

C#

Wpf

Xaml