title: Very very simple MVVM problem
body: <p>I am trying to make my very first Silverlight App ever, but I can't get the LogOn function to work, can you help me? This should properly be super simple for all of you, I will show you my two files: LogOn.xaml.cs and LogOnViewModel.cs</p>
  
  <p>Apparently the problem is that UserId gets not set early enough to be availble in LogOn.xaml.cx when I need it, can you help me make it work, that would lift my moment quite a bit :-)</p>
  
  <pre><code>public partial class LogOn : PhoneApplicationPage
  {
      public LogOn()
      {
          InitializeComponent();
          this.DataContext = LogOnViewModel.Instance;
      }
  
      private void btnLogOn_Click(object sender, RoutedEventArgs e)
      {
          if ((!string.IsNullOrEmpty(txtEmailAddress.Text)) &amp;&amp; (!string.IsNullOrEmpty(txtPassword.Password)))
          {
              txbLogonMessage.Text = "";
              LogOnViewModel.Instance.UserLogin(txtEmailAddress.Text, txtPassword.Password);
  
              if (LogOnViewModel.Instance.UserId &gt; 0)
                  NavigationService.Navigate(new Uri("/_2HandApp;component/Views/Main.xaml", UriKind.Relative));
              else
                  txbLogonMessage.Text = "Login was unsuccessful. The user name or password provided is incorrect. Please correct the errors and try again. ";
          }
      }
  }
  
  
  public sealed class LogOnViewModel : INotifyPropertyChanged
  {
      public static LogOnViewModel Instance = new LogOnViewModel();
      //public static int userId;
  
      private SHAServiceClient WS;
  
  private int userId;
      public int UserId
      {
          get
          {
              return userId;
          }
  
          set
          {
              userId = value;
              this.RaisePropertyChanged("UserId");
          }
      }
  
  
  private LogOnViewModel()
      {
          WS = new SHAServiceClient();
          WS.UserLoginCompleted += new EventHandler&lt;UserLoginCompletedEventArgs&gt;(WS_UserLoginCompleted);
      }
  
      void WS_UserLoginCompleted(object sender, UserLoginCompletedEventArgs e)
      {
          if (e.Error == null)
          {
              this.UserId = e.Result;
          }
      }
  
  
      public void UserLogin(string email, string password)
      {
          WS.UserLoginAsync(email, password);
      }
  
  /* Implementing the INotifyPropertyChanged interface. */
      public event PropertyChangedEventHandler PropertyChanged;
      private void RaisePropertyChanged(string propertyName)
      {
          PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
          if ((propertyChanged != null))
          {
              propertyChanged(this, new PropertyChangedEventArgs(propertyName));
          }
      }
  }
  </code></pre>