Reputation: 129
In the first window of my App there is a button to open a second window and in the second window there is also a button to open a third window. All Button-Commands are implemented in my ViewModel. The current window must be closed before a new window is opened. To go from the first to the second window, I used the following code:
void OpenSecondWindowExecute()
{
System.Windows.Application.Current.MainWindow.Hide();
SecondWindow sw = new SecondWindow();
sw.WindowStartupLocation = WindowStartupLocation.CenterScreen;
sw.Show();
}
bool CanOpenSecondWindowExecute()
{
return true;
}
public ICommand OpenSecondWindow { get { return new RelayCommand(OpenSecondWindowExecute, CanOpenSecondWindowExecute); } }
and it works fine because first window represents the MainWindow.
Problem: How can I realize this with the other windows?
Upvotes: 1
Views: 549
Reputation: 1155
try this:
void OpenSecondWindowExecute()
{
this.Close();
SecondWindow sw = new SecondWindow();
sw.WindowStartupLocation = WindowStartupLocation.CenterScreen;
sw.Show();
}
Upvotes: 1