locked
MVVM, Textbox value passed from model RRS feed

  • General discussion

  • Hello,

    I have looked at different sites but haven't found the solution.

    These are my folders in a Visual studio project

    Folder Models.

    user.cs 

    private string userName; public string UserName { get {return userName } set { userName = value }

    OnPropertyChanged(); }

    Folder ViewModels

    funnyUserVM.cs

    private void insertAUser()
    
    {
    user userInfo = new user()
    
    {
        UserName = "Turtleman"
    }
    
    }

    Now obviously if this wasn't an MVVM type of design I would simply grab a caller as textbox and get the inserted value but since I'm trying to use the MVVM pattern I know I should bind this to a two-way textbox. Given the fact that my model-class is in a different file and not in the actual viewmodel I don't know how to do this.

    edit: And by that I mean that I don't know how to NOT send anything in my insertAUser since I know that my textbox binding twoway will take care of the value set in the View.


    Friday, June 6, 2014 7:46 AM

All replies

  • Typically I've seen in a done in a couple of ways. 1) Keep the two in sync - the view model contains a model and keeps the properties in sync via property changes 2) Load/Save - The view model is loaded with the model data. The two then go out of sync until the view model saves, then it writes to the model. 1) has an advantage that you can call validate function that are contained in the model


    http://pauliom.wordpress.com

    Friday, June 6, 2014 8:08 AM
  • Typically I've seen in a done in a couple of ways. 1) Keep the two in sync - the view model contains a model and keeps the properties in sync via property changes 2) Load/Save - The view model is loaded with the model data. The two then go out of sync until the view model saves, then it writes to the model. 1) has an advantage that you can call validate function that are contained in the model


    http://pauliom.wordpress.com

    Hi pkr2000.

    What do you mean with number 1? Having the code for my model user.cs in my viewmodel instead?

    Friday, June 6, 2014 8:20 AM
  • No containment, e.g. private MyModel myContainedModel


    http://pauliom.wordpress.com

    Friday, June 6, 2014 10:34 AM
  • Thanks. It was helpful.
    Saturday, June 7, 2014 8:53 PM