2011-02-26 26 views

回答

0

恩,奇怪,這是沒有回答...我個人用ElementHost來實現這一點。

下面是一個例子的相關詳細: Put WPF control into a Windows Forms Form

例如,我們有噸的WinForm形式的老WinForm應用程序。但是,每個新開發的Windows都是在WPF中完成的。

爲了能夠顯示每一個新的WPF的形​​式:

  1. 我們有一個主要的WinForm形式有它很大的ElementHost的[只有]
  2. 然後,當我想顯示一個WPF窗口,我做類似的電話:

//create the winform Hoster, which contains a ElementHost on it 
form_MyWPF_Hoster MyForm = new form_MyWPF_Hoster(); 

//Create the instance of your WPF control 
form_WPFNewWindows MyWPF = new form_WPFNewWindows(); 

//Add the WPF control to the elementHost (it is publicly accessible...i know, it's bad..) 
MyForm.elementHost1.child = MyWPF ;  

//show the WinForm : 
MyForm.ShowDialog(); 
+0

它被回答了,但最近被mod刪除了,因爲發佈的答案只提供了鏈接而沒有解釋。 – LarsTech 2015-09-25 19:16:57

+0

已刪除答案中的鏈接全部過期,導致答案無用。 – 2015-09-25 19:37:38

1

This article詳細解釋瞭如下回答。

using System; 
using System.Windows.Forms; 
using System.Windows.Forms.Integration; 

var wpfwindow = new WPFWindow.Window1(); 
ElementHost.EnableModelessKeyboardInterop(wpfwindow); 
wpfwindow.Show();