Public classUser:Private string_user; Public stringUser1 {Get{return_user;} Set{_user=value; } } Private string_password; Public stringPassword {Get{return_password;} Set{_password =value;} } } }
User u; Private voidButton_click_1 (Objectsender, RoutedEventArgs e)//Click the login button to pop up the new form { //first determine if the user name and password are correctU =NewUser (); U.user1="Admin"; U.password="123"; if(string. Isnullorwhitespace (TextBox1.Text))//determine if the value of the User name box is not empty{MessageBox.Show ("user name is empty"); } Else { if(TextBox1.Text = = U.user1 && Textbox2.password = =U.password) {Window1 F=NewWindow1 (U);//You pass the entity class U to the form you just opened so that the form you just opened can call the entity class.f.show (); This. Owner =F; This. Hide (); } Else{MessageBox.Show ("The user name or password is incorrect"); } } }
The following click on the login, the input text to the new form, the method is to bind the entity class user, by binding the data inside the user to achieve the value of the pass.
The Binding property is Bindint User1 (User1 is the username attribute in the entity class user) Mode=default is the binding method
Then assign a value to two text boxes in the new form, and the content of the assignment is the contents of the attributes in the user of the bound entity class.
Public Partial classWindow1:window {User U;//as with the previous transmission of the form, transfer variables, here is the entity class; PublicWindow1 (User u) {initializecomponent (); U=u; //TextBox1.Text = u.user1 + "\ n" + U.password;//"\ n": Line breakTextbox1.datacontext = U;//the data source of the text box 1 is the entity class U, when you just drag into the text box 1, the text box 1 is bound to the user name (User1) attribute in the entity class userTextbox2.datacontext = U;//the data source of the text box 2 is the entity class U, when you just drag into the text box 2, the text box 2 is bound to the entity class User password (Password) attribute } }
wpf--entity classes and binding entity class properties