mvvm - Binding a save command WPF -
I have 3 text boxes in a grid - this is my view - and I have a Save button In my user list with datas from the text box, I want to use a relay command to do this on my view-model class, but I'm quite confused about how to bind. I hope it is quite clear that any thoughts or examples can be useful thanks in advance.
You should have something like the following:
class UserViewModel {public string name {get; Set; } Public string password {get; Set; } Public String Email {get; Set; } Public Relations AddUserCommand {get; Set; } Public User Review () {AddUserCommand = New Relay Commands (AddUser); } Zero AddUser (object parameter) {// code to add user here. }}
And you can use it like this:
& lt; StackPainel & gt; & Lt; Text box text = "{binding name}" & gt; & Lt; / Textbox & gt; & Lt; Text box text = "{binding password}" & gt; & Lt; / Textbox & gt; & Lt; Text box text = "{binding email}" & gt; & Lt; / Textbox & gt; & Lt; Button command = "{Binding AddUserCommand}" & gt; Add & lt; / Button & gt; & Lt; / StackPanel & gt;
To make this work, insert the following code into the constructor of your usercontrol / control / window:
DataContext = New UserViewModel ();
Comments
Post a Comment