簡體   English   中英

如何檢查WPF控件是否托管在WinForms中?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM