Click here to Skip to main content
15,884,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi forum,

there's a software written in Windows Forms that connects the output of a DirectShow filter graph to a panel.
hr = videoWin.put_Owner( videoPanel.Handle );

How do I obtain the handle of a XAML Rectangle, MediaElement, Border or ContentControl?
And what would be the control to use for displaying a video?

What I have tried:

I have reflected and speculated.
Posted
Updated 29-Sep-20 22:20pm

Getting the handle requires a little bit of PresentationSource trickery. Your code will look something like this:
C#
HwndSource hwnd = PresentationSource.FromVisual(theControl) as HwndSource;
if (hwnd != null)
{
  handle = hwnd.Handle;
}
 
Share this answer
 
If I understand correctly, you seek to play video in WPF and need events possible with it.

Have a look at these:
Playing video - The complete WPF tutorial[^]
MediaElement Class Events (Windows.UI.Xaml.Controls) - Windows UWP applications | Microsoft Docs[^]

Example:
HTML
<Window x:Class="WpfTutorialSamples.Audio_and_Video.MediaPlayerVideoSample"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MediaPlayerVideoSample" Height="300" Width="300">
    <Grid>
        <MediaElement Source="http://hubblesource.stsci.edu/sources/video/clips/details/images/hst_1.mpg" />
    </Grid>
</Window>
 
Share this answer
 
Comments
lukeer 30-Sep-20 4:30am    
Actually, I need to display a live video from a USB camera, not from file. What would I have to set MediaElement.Source parameter to to capture from my camera?
Sandeep Mewara 30-Sep-20 4:34am    
Make use of:
https://github.com/Sascha-L/WPF-MediaKit

Another example:
https://www.codeproject.com/Articles/285964/WPF-Webcam-Control

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900