How to get a handle to a User-Control in WPF

We are in the process of integrating a 3rd-party video application with our software.  

Our UI for the video is being done in a WPF user-control.  The API from the 3rd-party requires a handle to the Image control in our user-control so the API can "draw" video to the control.

We're struggling with how to obtain the handle for the Image control inside the user-control.

Any help is greatly appreciated.
LVL 11
CMYScottAsked:
Who is Participating?
 
Roshan DavisCommented:
HwndSource source = PresentationSource.FromVisual(imageControl) as HwndSource;
IntPtr32 handle = source.Handle;
0
 
Roshan DavisCommented:
if you know the Control ID of that image
userCtril.FindControl("Control ID") should work
0
 
Roshan DavisCommented:
can can you expose a property in your user control that returns the Handle of the imageCtrol?
public System.IntPtr32 ImageHandle
{
   get
   {
      return imageControl.Handle;
   }
}

Open in new window

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
CMYScottAuthor Commented:
@roshmon

Unless I'm missing something - the problem is that the WPF controls do not expose a 'Handle' property at all
0
 
Roshan DavisCommented:
can you try this

HwndSource source = PresentationSource.FromVisual(imageControl) as HwndSource;

Open in new window

0
 
CMYScottAuthor Commented:
I can - but I don't see how that relates to giving me the handle to the control?

PresentationSource doesn't seem to have a property that exposes the handle.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
For more info see:
http://msdn.microsoft.com/en-us/library/system.windows.interop.hwndsource.aspx

    "The HwndSource class is designed for general interoperability and is not designed as a managed HWND wrapper. In general, it does not provide managed methods for manipulating the window or properties for inspecting its state. Instead, the HwndSource class provides access to the Win32 window handle (HWND) through the Handle property, which can be passed by means of PInvoke techniques to Win32 APIs in order to manipulate the window."
0
 
CMYScottAuthor Commented:
It's still not working 100% - the video is being 'drawn' into the entire parent-window of the control, perhaps the API we're using is doing that though.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.