[DllImport("user32.dll")]
public static extern int GetParent(int hwnd);
public int GetParentWindowHandle(Visual child)
{
HwndSource presentationSource = (HwndSource)PresentationSource.FromVisual(child);
int parentHandle = presentationSource.Handle.ToInt32();
int handle = parentHandle;
while (parentHandle != 0)
{
handle = parentHandle;
parentHandle = ApplicationHelperInterop.GetParent(parentHandle);
}
return handle;
}
Затем вы можете просмотреть коллекцию System.Windows.Forms.Application.OpenForms
, чтобы найти WinForm, соответствующую возвращаемому значению метода GetParentWindowHandle, приведенному выше.
Алекс Д.