在同一应用程序中的 WPF 和 WinForms 之间导航 [英] Navigating between WPF's and WinForms in the same application

查看:27
本文介绍了在同一应用程序中的 WPF 和 WinForms 之间导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是visual basic 的新手,目前正在visual studio 2015 中编码.我正在自学visual basic(大约2-3 周).我在一家船经销店工作,我正在尝试创建一个应用程序,我们可以在船展上使用该应用程序,客户可以在那里使用计算机并基本上选择他们想要的带有所有附加选项的船(任何钓鱼竿支架,不同颜色的运输,电机等).

I'm new to visual basic and I am currently coding in visual studio 2015. I am teaching myself visual basic (roughly 2-3 weeks). I work for a boat dealership, and I'm attempting to create an application that we can use at a boat show where Customers can come up to a computer and basically pick out a boat they want with all the additional options (any fishing rod holders, different color haul, motor etc).

到目前为止:

我正在使用 Visual Basic 并决定使用 WPF.我目前让我的程序在默认的主 MainWindow 上启动.在那个 MainWindow 里面是我托管所有未来页面"的地方

I am using visual basic and decided I wanted to use WPF's. I currently have my program start up on the default the main MainWindow. Inside that MainWindow is where I host all of my future 'pages'

Title="MainWindow" Height="850" Width="1200" Source="ChooseYourAdventure.xaml" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" WindowState="Maximized">

Title="MainWindow" Height="850" Width="1200" Source="ChooseYourAdventure.xaml" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" WindowState="Maximized">

从这里我让客户选择他们感兴趣的船,然后他们单击一个按钮,然后将他们切换到仍在 MainWindow 中托管的新页面".在新的页面"上,他们选择了电机,然后再次单击一个按钮并转到一个新的页面",在那里他们最终选择了他们感兴趣的拖车类型.

From here I have the customer choose which boat they are interested in and they click a button which then switches them to a new 'page' being hosted in MainWindow still. On the new 'page' they choose the motor, and once again click a button and go to a new 'page' where they finally choose the trailer type they are interested in.

这就是我遇到困难的地方

在预告片页面"之后,我希望能够获取客户信息(名字、姓氏等)并将其添加到数据库中.由于我不熟悉visual basic,尤其是WPF,我不知道这里的策略是什么.到目前为止,我在谷歌上搜索的所有内容都显示了如何通过使用表单"将记录添加到数据库中.

After the trailer 'page' I want to be able to take in the customers information(First name, last name, etc...) and add it to a database. Since I am unfamiliar with visual basic and especially with WPF's I have no clue what the strategy here is. Everything I've googled thus far always shows how to add records to a database through the use of 'Forms'.

我的想法是在大多数应用程序中使用 WPF,然后在需要为数据库输入客户信息时切换到表单"

我的问题是:是否可以从 WPF页面"导航到表单"?

推荐答案

您可以将主项目创建为 WPF 应用程序,并将其他项目创建为 Windows 窗体应用程序并将其输出类型设置为Class Library.
然后在主项目(WPF Application)中添加对其他项目(Windows Forms Application)的引用.
现在您可以在主项目中使用其他项目的所有表单和类.为此,只需在其中实例化其他项目的表单并显示即可.

You can create your main project as a WPF Application and your other project as a Windows Forms Application and set its output type as Class Library.
Then in main project (WPF Application) add a reference to other project (Windows Forms Application).
Now you can use all of the forms and classes of other project in your main project. To do so, it is enough to instantiate a form of other project in and show it.

例如,如果 Windows Forms Application 包含一个 Form1,您可以在主项目的按钮单击处理程序中使用此代码:

For example if Windows Forms Application contains a Form1, you can use this code in button click handler of your main project:

//Instead of NameSpace put the namespace of Form1
var f= new NameSpace.Form1();
f.Show();

进一步,如果你想在你的wpf表单中使用windows窗体创建的UseControl,你可以使用WindowsFormsHost

这篇关于在同一应用程序中的 WPF 和 WinForms 之间导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆