c# - Close WPF window that host Pages -


im learning c# wpf. im trying understand how navigation works.

i have created test app includes 2 buttons. 1 navigates next page , open new window.

navigation between pages not problem. able navigate page1 page2 using button. code below written in page1.xaml.cs

private void button_click(object sender, routedeventargs e)     {         page2 p2 = new page2();         this.navigationservice.navigate(p2);     } 

the problem when try open new window , close previous 1 button, doesnt work. (i wrote on page1.xaml.cs)

private void button_copy_click(object sender, routedeventargs e)     {         window1 win1 = new window1();         win1.show();         this.close();     } 

its giving me error code cs1061 , telling me not contain definition 'close' .....

here complete code of page1.xaml.cs:

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.windows; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.navigation; using system.windows.shapes;  namespace wpfapplication1 {     /// <summary>     /// interaction logic page1.xaml     /// </summary>     public partial class page1 : page     {         public page1()         {             initializecomponent();         }          private void button_click(object sender, routedeventargs e)         {             page2 p2 = new page2();             this.navigationservice.navigate(p2);         }          private void button_copy_click(object sender, routedeventargs e)         {             window1 win1 = new window1();             win1.show();             this.close();         }     } } 

it's bit of guess, haven't seen enough of code. if call this.close() placed outside class defining window you're trying close, there's no such method in scope of this.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -