videoCapElement doesn't play again after switching tabs

Jan 28, 2013 at 4:45 AM
Edited Jan 28, 2013 at 4:47 AM

i have a videoCapElement on tab 2

window opens with tab 1 on the front

when i swtch to tab 2, i bind devices to a combobox

when i change selection on combobox, i set source and play videoCapElement and it works!

when i switch back to tab 1 and then to tab 2, nothing happens

so i figure i need to reload the videoCapElement, how do i do it?

<WPFMediaKit:VideoCaptureElement 
Grid.Row="1" 
x:Name="videoCapElement"
Stretch="Fill"
FPS="30" 
Margin="10,10,0,0" />
private void tabVisit_SelectionChanged(object sender, SelectionChangedEventArgs e)
	{
		if (e.OriginalSource != tabVisit )
			return;

		if ((TabItem)tabVisit.SelectedItem == tabitemPhotos)
		{
			cbxImageDevices.ItemsSource = null;
			cbxImageDevices.ItemsSource = MultimediaUtil.VideoInputDevices;
			cbxImageDevices.DisplayMemberPath = "Name";                   
		}
	}
private void cbxImageDevices_SelectionChanged(object sender, SelectionChangedEventArgs e)
	{
		if (cbxImageDevices.SelectedIndex != -1)
		{
			videoCapElement.VideoCaptureSource = ((WPFMediaKit.DirectShow.Interop.DsDevice)cbxImageDevices.SelectedItem).Name;
			videoCapElement.Play();
		}
	}

Jan 28, 2013 at 5:09 AM

did this workaround:

 

private void cbxImageDevices_SelectionChanged(object sender, SelectionChangedEventArgs e)
	{
		if (cbxImageDevices.SelectedIndex != -1)
		{
			string name = ((WPFMediaKit.DirectShow.Interop.DsDevice)cbxImageDevices.SelectedItem).Name;
			frameVideoCapElement.Navigate(new VideoCaptureElement(name));
			frameVideoCapElement.NavigationUIVisibility = System.Windows.Navigation.NavigationUIVisibility.Hidden;                
		}
	}
<Page x:Class="PatientRecordsWPF2.VideoCaptureElement"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:WPFMediaKit="clr-namespace:WPFMediaKit.DirectShow.Controls;assembly=WPFMediaKit"
      mc:Ignorable="d" 
      d:DesignHeight="300" d:DesignWidth="300"
	Title="VideoCaptureElement">

    <Grid>
        <WPFMediaKit:VideoCaptureElement x:Name="videoCapElement"
                			Stretch="Fill"
                			FPS="30" />
    </Grid>
</Page>
public VideoCaptureElement(string name)
		: this()
	{
		videoCapElement.VideoCaptureSource = name;
		videoCapElement.Play();
	}