2015-04-05 148 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