How to Pass Value from one form to another Form in WPF

Just make a overload constructor which takes parameters of the window in which you want to retrieve.

Example

Suppose we want a user to login from our Main Window( i.e Login Window ) and we want to pass an int ID / string Email to our second form to retrieve data of logging user. Than We have to first overload our second wpf form constructor.

Use can either make default constructor to do this or make an overload constructor for this work.

SecondForm:

  1. public secondForm()  
  2. {  
  3.    //Your Default Constructor Logic  
  4. }  
  5. public secondForm(string email_ )  
  6. {  
  7.    //Your Overload Constructor Logic  

Now in MainWindow from where we are logging and passing our EMail

MainWindow:

  1. public void btnLogin()  
  2. {  
  3.    //On Success  
  4.   
  5.    SecondWindow sw = new SecondWindow(txtBoxEMail.Content);  
  6.    sw.Show();  

 

Next Recommended Reading WPF Binding One Way and Two Way