title: How to pass data between the View and the ViewModel
body: <p>I'm a newbie in the MVVM design patter I'm trying to create a simple app where a list of students is shown in the main window and I want the user to be able to add a new student to the list I have accomplished the binding of the observable collection where the students' data are but how can I create a new user by fetching the data from the textboxes and using them as a parameter in a command </p>
  
  <p>Here is my View</p>
  
  <pre><code>&lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="2*"/&gt;
          &lt;RowDefinition Height="2*"/&gt;
          &lt;RowDefinition Height="2*"/&gt;
          &lt;RowDefinition Height="*"/&gt;
          &lt;RowDefinition Height="Auto"/&gt;
          &lt;RowDefinition Height="*"/&gt;
          &lt;RowDefinition Height="Auto"/&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="Auto"/&gt;
          &lt;ColumnDefinition Width="*"/&gt;
      &lt;/Grid.ColumnDefinitions&gt;
  
      &lt;TextBlock x:Name="NameTextBlock"
                 Text="Name"
                 Style="{StaticResource TextBlockTextStyle}"/&gt;
      &lt;TextBlock x:Name="SurnameTextBlock"
                 Grid.Row="1"
                 Text="Surname"
                 Style="{StaticResource TextBlockTextStyle}"/&gt;
      &lt;TextBlock x:Name="AgeTextBlock"
                 Grid.Row="2"
                 Text="Age"
                 Style="{StaticResource TextBlockTextStyle}"/&gt;
      &lt;TextBox x:Name="NameTextBox"
               Grid.Column="1"
               Style="{StaticResource TextBoxTextStyle}"/&gt;
      &lt;TextBox x:Name="SurnameTextBox"
               Grid.Row="1"
               Grid.Column="1"
               Style="{StaticResource TextBoxTextStyle}"/&gt;
      &lt;TextBox x:Name="AgeTextBox"
               Grid.Row="2"
               Grid.Column="1"
               Style="{StaticResource TextBoxTextStyle}"/&gt;
      &lt;ListBox x:Name="StudentListBox"
               Grid.ColumnSpan="2"
               Grid.Row="4"
               Style="{StaticResource ListBoxStyle}"
               ItemsSource="{Binding StudentList}"&gt;
          &lt;ListBox.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;Grid&gt;
                      &lt;Grid.ColumnDefinitions&gt;
                          &lt;ColumnDefinition Width="Auto"/&gt;
                          &lt;ColumnDefinition Width="Auto"/&gt;
                          &lt;ColumnDefinition Width="Auto"/&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
                      &lt;TextBlock Text="{Binding Name}"
                                 Style="{StaticResource TextBlockTextStyle}"/&gt;
                      &lt;TextBlock Text="{Binding Surname}"
                                 Grid.Column="1"
                                 Style="{StaticResource TextBlockTextStyle}"/&gt;
                      &lt;TextBlock Text="{Binding Age}"
                                 Grid.Column="2"
                                 Style="{StaticResource TextBlockTextStyle}"/&gt;
                  &lt;/Grid&gt;
              &lt;/DataTemplate&gt;
          &lt;/ListBox.ItemTemplate&gt;
      &lt;/ListBox&gt;
      &lt;Button x:Name="AddButton"
              Grid.Row="7"
              Grid.ColumnSpan="2"
              HorizontalAlignment="Center"
              Content="Add"
              Margin="7,7,7,7"
              Command="{Binding AddStudentCommand}"/&gt;        
  &lt;/Grid&gt;
  </code></pre>
  
  <p>And here is my ViewModel</p>
  
  <pre><code>public class MainViewModel : ViewModelBase
  {
      ObservableCollection&lt;Student&gt; studentList;
      public MainViewModel()
      {
          //populate some sample data
          studentList = new ObservableCollection&lt;Student&gt;()
          {
              new Student(){Name="John", Surname="Smith", Age="28"},
              new Student(){Name="Barbara", Surname="Anderson", Age="23"}
          };
      }
  
      public ObservableCollection&lt;Student&gt; StudentList
      {
          get { return studentList; }
          set { RaisePropertyChanged("studentList"); }
      }
  
      Student selectedPerson;
      public Student SelectedPerson
      {
          get { return selectedPerson; }
          set
          {
              selectedPerson = value;
              RaisePropertyChanged("SelectedPerson");
          }
      }
  
      private RelayCommand _addStudentCommand;
      public ICommand AddStudentCommand
      {
          get
          {
              return _addStudentCommand
                  ?? (_addStudentCommand = new RelayCommand(() =&gt;
                  {
                      Student student = new Student();
                      // here should be the logic of defining the name, surname, 
                      // age and id of the newly created student
                      studentList.Add(student);
                  }));
          }
      }
  
  }
  </code></pre>
  
  <p>I am using MVVMLight in the current project and there are a lot of thing that I do not understand so please explain how I should pass the data of the textboxes and what exactly should happen in the command that it is being used.</p>
  
  <p>Tell me to add more of the code if necessary. </p>