tags:

views:

71

answers:

1

I have a situation where I need to find the parent Window or WinForm which is hosting the WPF control. I need to get the handle of either the parent Window or WinForm whatever the case may be.

The problem is when the WPF control is hosted in a WinForm using ElementHost. How can I find the Handle of the hosting WinForm from a WPF control.

A: 

Just figured it out!

var presentationSource = (HwndSource)PresentationSource.FromVisual(child);
var parentHandle = presentationSource.Handle;
Trainee4Life