[英]WPF Change between 2 windows
I have been searching everywhere for the answer to my problem but i cant seem to locate anything. 我一直在到处寻找问题的答案,但是我似乎找不到任何东西。
I am trying to open 2 different windows, that i have already created, after a button press. 按下按钮后,我试图打开2个已经创建的不同窗口。 On the button press, i go to open the new window, but it just opens a blank window, not the window i want. 在按下按钮时,我去打开新窗口,但是它只是打开一个空白窗口,而不是我想要的窗口。
This is my function that i am trying to open my new window with, and it is inside my MainWindow, and i want to open my window i have created in Jobs (see image below). 这是我尝试打开新窗口的功能,它在MainWindow内,我想打开在Jobs中创建的窗口(请参见下图)。
void Jobs_Clicked(object sender, RoutedEventArgs e)
{
Window Jobs_Window = new Window();
App.Current.Jobs = Jobs_Window;
Jobs_Window.Show();
this.Close();
}
You are creating an instance of the standard Window class rather than your custom Window that you have made. 您正在创建标准Window类的实例,而不是创建的自定义Window。
If you have added a Window, called JobsWindow for example, then create an instance of that rather than just the .NET built-in Window: 如果添加了一个窗口,例如称为JobsWindow的窗口,则创建该窗口的实例,而不仅仅是.NET内置窗口:
void Jobs_Clicked(object sender, RoutedEventArgs e)
{
Window Jobs_Window = new JobsWindow();
App.Current.Jobs = Jobs_Window;
Jobs_Window.Show();
this.Close();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.