Hi friends,private void btn1_Click(object sender, RoutedEventArgs e)
{
Window2 win2 = new Window2();
win2.ShowDialog();
this.close();
}
it is not close window., so i modify the code,..
private void btn1_Click(object sender, RoutedEventArgs e)
{
Window2 win2 = new Window2();
// win2.Owner = this;
win2.Show();
this.Close();
}
Now the window is close but,... the window2 is show empty,. it didn''t show any button or labels. if minimize and maximize the window only it show the buttons,.
What can i do?. :rolleyes:
解决方案Ok, I could not reproduce your problem. I do this in a button click handler on the main form:
private void button1_Click(object sender, RoutedEventArgs e)
{
Child child = new Child();
child.Show();
this.Close();
}
The child window shows up correctly (no painting issues at all). So you may be doing something else in your code that''s causing problems.
First code sample should show dialog but not close the this window only after dialog is closed (because it is modal).
The second sample should work as expected. The newly created Window should be shown.
It it does not show its content at first, it can happen by different reasons related to design of Window2; one typical reason is incorrect layout. Try to call its InvalidateArrange and/or UpdateLayout. If it helps, this is not a solution yet. Check up overloaded OnContentRendered, OnRender is any. It also can be a result of incorrect behavior on window resize events. just for tests, make is resizeable (if it is not) and check if it does not screw up layout when you manually resize it.
—SA
I am unable to close one file,. so switch to close all but this method,.
its not a correct sollution of this problem,. but it solves that,.
i find this code in our Code project here.
I hope feature also this code has not give problems,..
private void CloseAllWindows()
{
for (int intCounter = App.Current.Windows.Count - 1; intCounter > 0; intCounter--)
App.Current.Windows[intCounter].Close();
}
private void btn1_Click(object sender, RoutedEventArgs e)
{
CloseAllWindows();
Window2 win2 = new Window2();
// win2.Owner = this;
win2.Show();
//this.Close();
}
Thank to all,.