Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
Posted
Updated 11-Feb-11 23:55pm
v2
Comments
TweakBird 12-Feb-11 5:56am    
Please uncheck 'Ignore HTML' Check box. If your post contains code blocks.
Sagotharan Jagadeeswaran 12-Feb-11 6:28am    
ok friend,..
Nish Nishant 12-Feb-11 8:56am    
Are you sure you are using WPF? The painting issues seem to indicate Winforms.
Nish Nishant 12-Feb-11 8:58am    
Never mind. I saw the class names. You are using WPF.

Ok, I could not reproduce your problem. I do this in a button click handler on the main form:

C#
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.
 
Share this answer
 
Comments
Sagotharan Jagadeeswaran 12-Feb-11 9:54am    
Thank U. but my problem was not solved. I try this code.

Any other have solution tell me pls,..
Nish Nishant 12-Feb-11 10:03am    
Unless you show a minimal code snippet that reproduces the bug, I don't think anyone can figure out what's wrong.

Create a new wpf project, add a child window, then try the same code out and see if that works for you. That will be a good first step in trying to establish the source of the problem.
Sagotharan Jagadeeswaran 14-Feb-11 1:52am    
This method is very nice. i try. but the same error was thrown.

I think its my layout problem,. (as SAKryukov told) if i give time to press its not happen,. then i find a solution. i post that answer 3.,
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
 
Share this answer
 
v2
Comments
Sagotharan Jagadeeswaran 13-Feb-11 23:14pm    
Thank u very much,.
Sergey Alexandrovich Kryukov 13-Feb-11 23:34pm    
Did you find out anything?
--SA
Sagotharan Jagadeeswaran 14-Feb-11 2:02am    
now i find a solution. (thank to my friend naganathan),., i post that in below,.
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,.
 
Share this answer
 
v2

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