I have two windows: MainWindow and Window2
1) On the initial opening of the application I would like Window2 to open.
2) When I click the button on Window2 it will close this window and MainWindow will open. (If I close Window2 instead of clicking the button, then I want the app to shut down)
3) MainWindow will now be the only window open.
4) When I click the button on MainWindow it will open Window2 as a DIALOG window.
5) When Window2 is open as a dialog, I want to be able to close the dialog and STILL HAVE MainWindow OPEN. (***currently, the app shuts down when I close the dialog window)
How can I accomplish these goals?
The main problems with the below app is that: Window2 doesn't open FIRST and closing the dialog window WHILE MainWindow is open shuts down the app.
MainWindow XAML:
<Window x:Class="WpfApplication41.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"><Grid><Button Content="Open Window2" Height="29" HorizontalAlignment="Left"
Margin="184,51,0,0" Name="button1" VerticalAlignment="Top" Width="125" Click="button1_Click" /></Grid></Window>MainWindow C#:
namespace WpfApplication41
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Window2 win2 = new Window2();
win2.WindowStartupLocation = WindowStartupLocation.Manual;
win2.ShowDialog();
this.Close();
}
}
}Window2 XAML:
<Window x:Class="WpfApplication41.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="335"><Grid><Button Content="Close this window" Height="27" HorizontalAlignment="Left"
Margin="78,42,0,0" Name="button1" VerticalAlignment="Top" Width="141" Click="button1_Click" /></Grid></Window>namespace WpfApplication41
{
public partial class Window2 : Window
{
public Window2()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
MainWindow win1 = new MainWindow();
win1.WindowStartupLocation = WindowStartupLocation.Manual;
win1.Show();
this.Close();
}
}
}