wpf - Choice to close the parent window when closing a child window -


i have main window opens subwindow using:

this.hide(); this.showintaskbar = false; login = new frmlogin(this);  login.closed += (s, args) => this.close(); login.show(); 

this works good, sub window opened , if user clicks x button, both windows close.

there button in window task however, , if successful, must reopen main window , close sub window:

// main reference main window, this. sub window main.showintaskbar = true; main.show(); main.bringintoview(); this.close(); 

when this.close called, main window close well. can't seem separate such if user clicks x button, closes if user login successfully, sub window closed , main window unhidden. if remove line:

login.closed += (s, args) => this.close(); 

then login work if user clicks x button, sub window closes main window still rubbing in background

you can in various way.

without changing can put boolean property in frmlogin,

public bool closemainform { get; private set; } 

default value should true, when don't need close main window can put false, like

... main.bringintoview(); this.closemainform = false; this.close(); ... 

and change event handler

login.closed += (s, args) => { if (login.closemainform) this.close(); }; 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -