I have two Windows (main window & sub window) in WPF Application. In main window I have a button that will minimize main window and sub window will be opened as maximized.
When I am closing the sub window, I need to restore main window.
Can anybody help?
Thanks
Loading
Kirtan PatelPosted Feb 25, 2010, 1:43 PM
Suppose you have Window1 and Window2 Windows1 is main Windows and Window2 is Sub Windows.
Window1 Button Code
----------------------------
private void button1_Click(object sender, RoutedEventArgs e)
{
Window2 w2 = new Window2(this);
w2.Show();
this.Hide();
}
Window 2 Code
-------------------
public partial class Window2 : Window
{
Window1 referenceWindow;
public Window2()
{
InitializeComponent();
}
// you need To Add Below Overloaded Constructor
public Window2(Window1 FormObject)
{
InitializeComponent();
referenceWindow = FormObject;
}
// In windows Closing event Write this
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
referenceWindow.WindowState = WindowState.Maximized;
referenceWindow.ShowActivated = true;
referenceWindow.Show();
}
}
Van MatizPosted Feb 25, 2010, 11:11 PM