Click here to Skip to main content
15,906,341 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have three windows, main and sub-main1 and sub-main2.

The main window has a Button, this Button opens the sub-main1 window. The main sub-main1has a Button, this Button opens the sub-main2 window.

The problem is: when I open sub-main1 and sub-main2 then closeing the sub-main1, the main window is automatically minimized (note: this problem happens only if the main window WindowState property is Maximized)

The code is in this link:
https://www.dropbox.com/s/fxi17uphwrnhwai/WpfApplication18.zip[^]
Posted
Updated 31-Aug-13 17:13pm
v3

I ran your exe as well as compiled it in MSV and it worked fine. The windows stayed maximized when I opened the other forms. Hopefully someone else will try running it and run into the same problem, but all looks fine when I ran it.
 
Share this answer
 
You can set the focus to mainwindow on Closed event of sub_window1 in MainWindow.Xaml.Cs

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    sub_window1 sub_window1 =new  sub_window1();
    sub_window1.Owner = this;
    sub_window1.WindowStartupLocation = WindowStartupLocation.CenterOwner;
    sub_window1.Show();

    sub_window1.Closed += sub_window1_Closed;
}

void sub_window1_Closed(object sender, EventArgs e)
{
    this.Focus();
}


Hope this will help you..
 
Share this answer
 
v2
Comments
tarekwarak0 2-Sep-13 6:33am    
Thanke you Ms.Paunam. But that will be some hard thing.
Punamchand Dhuppad 2-Sep-13 7:09am    
Then do one thing...
Make the owner null for your child window closing event inside the child window itself.
like - do this code inside class sub_window1

this.Closing += sub_window1_Closing;
void sub_window1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
this.Owner = null;
}

This is necessary to get the focus on your mainwindow.

Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900