通常您需要託管表單在WindowInteropHelper, 像在WPF窗口Button.Click事件處理程序如下:
C#:
private void button1_Click(object sender, RoutedEventArgs e) {
Form1 form = new Form1();
WindowInteropHelper wih = new WindowInteropHelper(this);
wih.Owner = form.Handle;
form.ShowDialog();
}
VB:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim form As New Form1()
Dim wih As New WindowInteropHelper(Me)
wih.Owner = Form.Handle
form.ShowDialog()
End Sub
當然,您需要添加項目的引用/導入和System.Windows.Forms.dll
a'Process.Start(「Winform.exe」);'可能是一種替代方法... –
是的,我也這樣做了,但WPF應用程序是一個登錄表單,所以我不認爲這是一個不錯的選擇。謝謝! –