I have a WPF control which in some cases exists as a component of WPF application and in the other is hosted in Windows Forms. How can I detect the second case (a WPF control is embedded inside WinForms)?
I'd try Window.GetWindow(ctrl); and would expect it to return null, in a hosted environment.
– Rand Random
1 Answers
3
votes
Try this:
HwndSource wpfHandle = PresentationSource.FromVisual(this) as HwndSource;
if (wpfHandle != null)
{
ElementHost host = System.Windows.Forms.Control.FromChildHandle(wpfHandle.Handle) as ElementHost;
if(host != null)
{
//hosted in ElementHost...
}
}
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more
Window.GetWindow(ctrl);
and would expect it to return null, in a hosted environment. – Rand Random