wpf C# Visual Studio 打开新窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18793363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# Visual Studio Open New Window
提问by Fernando Retimo
I am new to C# and Visual Studio, But I started a little project that opens a main window and shows a table. The Presenter of the window contains an Observable:
我是 C# 和 Visual Studio 的新手,但我开始了一个小项目,它打开一个主窗口并显示一个表格。窗口的 Presenter 包含一个 Observable:
public ObservableCollection<FruitsPresenter> Fruits { get; set; }
This collections contains information about some fruits. Then It shows a table of all i'ts content. I made a button that supposed to open a new window and create a 'entry form' that will ask for information and then add to the collection a new item.
此集合包含有关某些水果的信息。然后它显示了所有 i ts 内容的表格。我制作了一个按钮,它应该打开一个新窗口并创建一个“输入表单”,该表单将询问信息,然后将一个新项目添加到集合中。
I couldn't manage to do it. Any help?
我无法做到。有什么帮助吗?
回答by Max
Adding a new form and opening it is very simple in C#/Visual Studio.
在 C#/Visual Studio 中添加一个新表单并打开它非常简单。
Do the following:
请执行下列操作:
Add a new formto your project:
Do this by right-clicking your project and choose: Add -> Windows Form.
Name the form
Create new instance of form and call form:
向您的项目添加一个新表单:
为此,请右键单击您的项目并选择:添加 -> Windows 窗体。
为表单命名
创建新的表单实例并调用表单:
Go to the location where the new form should be called from. Add following code there:
转到应从中调用新表单的位置。在那里添加以下代码:
NewForm newFrm = new NewForm();
newFrm.Show();
New form will be visible when application calls code above.
当应用程序调用上面的代码时,新表单将可见。

