title: MVVM Light Binding
body: <p>Im working on a WPF project and use MVVM light. The textbox binding seem to not work. Do you have any idea why ? I use the INotifyPorpertyChanged implementation through the ViewModelBase Class implemented in the MVVM light framework.</p>
  
  <p>I have 2 textboxes Username and Password...and i would like that properties linked to these controls have their value changed when the user enters characters in both textfields.</p>
  
  <p>Thank you.</p>
  
  <p><strong>ViewModel</strong></p>
  
  <pre class="lang-cs prettyprint-override"><code>  #region Helpers Properties
  
          private UserBLL UserBLLManager;
          public UserBO User;
          public RelayCommand AddNewUserCommand { get; private set; }
          public RelayCommand TryToLoginCommand { get; private set; }
  
          #endregion
  
          public MainViewModel()
          {
              if (UserBLLManager == null)//service
                  UserBLLManager = new UserBLL();
  
              if (User == null)//model
                  User = new UserBO();
  
              AddNewUserCommand = new RelayCommand(() =&gt; AddNewUser());
              TryToLoginCommand = new RelayCommand(() =&gt; TryToLogin());
          }
  
  
              public void AddNewUser()
              {
                   //do stuff
  
              }
  
          }
      }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre class="lang-cs prettyprint-override"><code>public class UserBO:ObservableObject
          {   
              private string username;
              public string Username
              {
                  get { return username; }
                  set
                  {
                      if (value != username)
                      {
                          username = value;
                          RaisePropertyChanged("Username");
                      }
                  }
              }
  
              private string password;
              public string Password
              {
                  get { return password; }
                  set
                  {
                      if (value != password)
                      {
                          password = value;
                          RaisePropertyChanged("Password");
                      }
                  }
              }   
          }
  </code></pre>
  
  <p><strong>ServiceLocator</strong></p>
  
    <pre class="lang-cs prettyprint-override"><code>    public class ViewModelLocator
      {
  
          public ViewModelLocator()
          {
              ServiceLocator.SetLocatorProvider(() =&gt; SimpleIoc.Default);
  
  
              SimpleIoc.Default.Register&lt;MainViewModel&gt;();
  
          }
  
          public MainViewModel Main
          {
              get
              {
                  return ServiceLocator.Current.GetInstance&lt;MainViewModel&gt;();
              }
          }
  
          public static void Cleanup()
          {
              // TODO Clear the ViewModels
          }
  }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;Window x:Class="MyCook.MainView"
                  DataContext="{Binding Main, Source={StaticResource Locator}}"&gt;
  
              &lt;Grid&gt;
  
                          &lt;TextBox Name="Username_TxtBox" Text="{Binding User.Username,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"&gt;&lt;/TextBox&gt;
  
                          &lt;TextBox Name="Pwd_TxtBox" Text="{Binding User.Password,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" &gt;&lt;/TextBox&gt;
  
  &lt;/Grid&gt;
  </code></pre>