[英]Creating a form from a WinForms Control hosted within WPF — Owner is not set
[英]How to check if WPF control is hosted within WinForms?
我有一個WPF控件,在某些情況下,該控件作為WPF應用程序的組件存在,而在其他情況下,則托管在Windows Forms中。 如何檢測第二種情況(WinForms中嵌入了WPF控件)?
嘗試這個:
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...
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.