c# - Form dialog event not catched if ShowDialog() used instead of Show() -


i have created formmanager class shows custom form named myformview. formmanager subscribes event myformview throws.

here code side fires event @ myformview:

public delegate void myformclickeventhandler(string name); public event myformclickeventhandler myformeventhandler;  private void myformclick(object sender, routedeventargs e) {     if (this.myformeventhandler != null)     {         this.myformeventhandler(this.name.text);     } } 

formmanager creates myformview dialog , subscribes usercontrol event:

public delegate void myformeventhandler(string info); public static event myformeventhandler myformevent;  myformview = new window {     title = "my form!",     height = 300,     width = 980,     content = new myformview() }; ((myformview)myformview.content).myformeventhandler += this.getdatafromform; 

here show dialog use:

myformview.show(); 

the code works fine, event fired inside user control (myformview) , catched in actual event handler (getdatafromform).

the problem if change last defined line one:

myformview.showdialog(); 

the problem here event not fired because @ myformclick myformeventhandler null.

what difference between show() , showdialog() makes formmanager not subscribe event myformview? can solved?

the problem showed dialog before subscribing event.

using show() not problem, using showdialog() never subscribes event.

here code:

myformview = new window {     title = "my form!",     height = 300,     width = 980,     content = new myformview() };  ((myformview)myformview.content).myformeventhandler += this.getdatafromform;  myformview.show();  //or myformviewshowdialog(); 

actually arie 1 gave solution in comments, did not post it. ppl may have same issue.


Comments