WPF:单击按钮并打开新窗口不同的选项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15837036/
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
WPF: Click button and open new window different options
提问by user2240068
I'd like to make an application, where I can click a button and a new window appears, where new options/buttons are available. I already managed to create a new window win2 after clicking the button:
我想制作一个应用程序,我可以在其中单击一个按钮并出现一个新窗口,其中提供了新的选项/按钮。单击按钮后,我已经设法创建了一个新窗口 win2:
private void button1_Click(object sender, RoutedEventArgs e)
{
var win2 = new Window();
win2.Show();
this.Close();
}
Now how do I edit the new window. Let's say I want to make new buttons (named: blue, green....), where the user can chose a color for the background.
现在如何编辑新窗口。假设我想制作新按钮(命名为:蓝色、绿色....),用户可以在其中选择背景颜色。
回答by Andy
When you want to create a new Window, you cannot use the Window class directly because it acts as a template.
当你想要创建一个新的 Window 时,你不能直接使用 Window 类,因为它充当了一个模板。
To add a new Window to your project:
向项目添加新窗口:
Right Click on your Project --> Add --> New Element --> Window. Name it as you please, but I will use the default (Window1).
右键单击您的项目 --> 添加 --> 新元素 --> 窗口。随意命名,但我将使用默认值(Window1)。
Now you can operate on your new window in the same ways you did your original window. Add any UI elements you like and code them to your desire.
现在,您可以像操作原始窗口一样操作新窗口。添加您喜欢的任何 UI 元素并根据需要对其进行编码。
To show the new window:
要显示新窗口:
Window1 secondWindow = new Window1();
secondWindow.Show();