Click here to Skip to main content
16,013,918 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
OK what I am trying to do is as follows. My main window has a button(btnAdmin) that opens up a new window(Admin.xaml). From the Admin window the user enters a password then clicks ok. When password is entered correctly it will close that window and go back to main window and unlock 4 buttons that were previously locked.

What I'm trying to do is in the second window if password is right it will save a bool variable as true and when you go back to main window that bool variable will be passed to a method that will unlock 4 buttons.

Not sure if this is the right method or I should be doing something else.

What I have so far

Main.xaml.cs btnAdmin Click
C#
 private void btnAdminMode_Click(object sender, RoutedEventArgs 
            Admin admin = new Admin();
            admin.Show();
}


Admin.xaml.cs Window OK button click
C#
private void btnOK_Click(object sender, RoutedEventArgs e)
       {
           if (ptxtPassword.Password == "tqty")
           {
               string msgtext = "Correct!\nAdministrator Rights are now ON";
               string txt = "Password";
               MessageBoxButton button = MessageBoxButton.OK;
               MessageBox.Show(msgtext, txt, button);
               this.Close();
           }
           else
           {
               string msgtext = "Incorrect Password";
               string txt = "Password";
               MessageBoxButton button = MessageBoxButton.OK;
               MessageBox.Show(msgtext, txt, button);
           }
       }
Posted
Comments
Sergey Alexandrovich Kryukov 6-Oct-14 15:45pm    
Why would you bounce text between windows at all? :-)
Why having anything other than just one main window at all? I am serious: in most designs, this would be the best.
—SA
Bryan Fil 7-Oct-14 8:03am    
I am rewriting a c++ coded program in c# and it is one of the design requirements. The old program did it so they want this on to do it as well. Pretty much its just a pop-up asking for a password.
Sergey Alexandrovich Kryukov 7-Oct-14 11:08am    
This is even simpler. Password window should rather be modal (I did not even count modal windows in my advice above). Show it in some method returning some value or structure (username + password) based on the properties of controls.
—SA

First of all, please see my comment to the question.

See my past answer: Repeat wpf Datagrid data in another window text boxes[^].

—SA
 
Share this answer
 
In the end i used a modal window to achieve what i wanted like Sergey Alexandrovich Kryukov suggested in the comments
 
Share this answer
 

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