2015-04-05 143 views
0

我想從我的C#應用​​程序從WinForms切換到WPF。我的WinForms應用程序是MDI應用程序。我需要使它在WPF中也是MDI。如何鎖定新窗口到我的應用程序主窗口或該窗口上的畫布?我的子窗口無法到達應用程序主窗口之外。這個子窗口必須在主窗口的菜單項的點擊事件上顯示。WPF VS2013 - 添加新窗口作爲主窗口的子項目

+0

顯示一些屏幕截圖 – 2015-04-05 15:34:30

+0

在CodePlex上查看[WPF多文檔界面(MDI)](http://wpfmdi.codeplex.com/)。 – Clemens 2015-04-06 06:29:14

回答

-1

在你的情況下,最好的解決方案是使用System.Windows.Forms.Integration.ElementHost控制。此控件允許您放置任何您喜歡的WPF控件。請按照下列步驟: 1)在Windows窗體項目創建子窗體 2)內這種形式的代碼添加System.Windows.Forms.Integration.ElementHost控制 3)背後做smomething這樣的:

wpfElementHost.Child = new System.Windows.Controls.TextBlock() 
     { 
      Text = "Hello from WPF world.", 
      FontSize = 25, 
      FontStyle = System.Windows.FontStyles.Italic, 
      FontWeight = System.Windows.FontWeights.Bold, 
      TextAlignment = System.Windows.TextAlignment.Center 
     }; 

注我使用完全限定名稱,因爲Windows窗體和WPF有許多共同點。在我的情況下,wpfElementHost是System.Windows.Forms.Integration.ElementHost。您可以託管任何控件,例如只需創建自定義控件或用戶控件作爲類庫並在Windows窗體應用程序中使用它們。 希望這有助於。讓我知道如果我正確回答你的問題。

+0

不幸的是我們誤解了:(我不是寫WinForms應用程序,而是WPF,我需要一些WinForms功能 - 主要是在WPF中創建新項Window並將其設置爲主窗口的子項,並配置它不能脫離主窗口。 – dzilupl 2015-04-05 21:26:20