0

I'm using the the wpf-mediakit library to render a video stream from a usb camera for my desktop application.

Tha XAML:

<TabItem>
    <Grid>
        <controls:MediaUriElement x:Name="mediaUriElement" Grid.Row="1"
                              DeeperColor="False"
                              Margin="4"
                              Stretch="Uniform"/>
        <controls:VideoCaptureElement x:Name="cameraCaptureElement" Grid.Row="1"
                                  EnableSampleGrabbing="False"
                                  DeeperColor="False"
                                  Margin="4"
                                  Stretch="Uniform"/>
    </Grid>
</TabItem>

And the code-behind:

public MainWindow()
        {
            InitializeComponent();            

            cameraCaptureElement.VideoCaptureDevice = MultimediaUtil.VideoInputDevices[0];
        }

The problem is, when I switch tabs and return to this tab item, the stream does not render at all. As far as I could tell, this is some Tab Virtualization problem, but I was out of ideas on how to solve this. Also, ideally, I would not want to re-initialize the stream every time as it takes a couple of seconds to do so.

Standard_101
  • 325
  • 4
  • 14
  • 2
    put `cameraCaptureElement.VideoCaptureDevice = MultimediaUtil.VideoInputDevices[0];` in an event handler for loaded event of that tab item, it should be called again once you switch tabs. – XAMlMAX Apr 22 '21 at 16:21
  • Hi. Thanks for the reply. I actually managed to do something similar. Didn't see your comment earlier, unfortunately. One question though: Is there a better way? Currently, I do this: `VideoCaptureDevice = null;` when the tab selection changes from the camera. And then reloading it takes a couple of seconds. – Standard_101 Apr 23 '21 at 08:44

0 Answers0