首页 文章

WPF VS2013 - 添加新窗口作为主窗口的子项目[复制]

提问于
浏览
0

这个问题在这里已有答案:

我正试图在我的C#应用程序中从WinForms切换到WPF . 我的WinForms应用程序是MDI应用程序 . 我需要在WPF中使它成为MDI . 如何将新窗口锁定到我的应用程序主窗口或该窗口上的画布?我的子窗口无法进入应用程序主窗口 . 必须在主窗口的菜单项的点击事件上显示该子窗口 .

1 回答

  • -1

    在您的情况下,最好的解决方案是使用System.Windows.Forms.Integration.ElementHost控件 . 此控制允许您放置任何您喜欢的WPF控件 . 请按照下列步骤操作:1)在Windows窗体项目中创建子窗体2)在此窗体中添加System.Windows.Forms.Integration.ElementHost控件3)在后面的代码中执行如下操作:

    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窗体应用程序中使用它们 . 希望这有帮助 . 如果我正确回答了你的问题,请告诉我 .

相关问题