Actual state: I click in the Login Button and the ViewModel changes to the new View.
Desired state: I click the LoginButton (the LoginViewModel binds the with the view to get the Email and Password and verifies in the server the authenticity of the user and if its ok the request receives as answer the info about the user and changes the view)
What I know: change the views, bind the textbox, communication with the server (handling the request and the answers)
What I don't know: send from the LoginViewModel to the GeneralViewModel the answer with the info about the user, don't know how to maintain the PasswordBox instead of the TextBox for binding.
CODE: LoginView
<Grid Margin="0,0,-74.4,-11.8" HorizontalAlignment="Left" Width="800" Height="600" VerticalAlignment="Top">
<TextBox Text = "{Binding Email, Mode = TwoWay}" Style="{DynamicResource MyTextBox}" x:Name="textBoxEmail" VerticalContentAlignment="Bottom" HorizontalContentAlignment="Center" HorizontalAlignment="Center" Width="248" Margin="274,212,278,347" FontFamily="Segoe UI Semibold" />
<Image Source="C:\Users\Images\logo.png" x:Name="Logo" HorizontalAlignment="Left" Height="129" Margin="301,63,0,0" VerticalAlignment="Top" Width="151" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="0.091"/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
Sign up now! Forgot your Password? Click here!
LoginViewModel
class LoginViewModel : AViewModel
{
WifiAP wa;
#region fields
private string _email = null;
private TokenRequest tk;
public DelegateCommand LoginCommand { get; set; }
public string Email
{
get
{
return _email;
}
set
{
_email = value;
OnPropertyChanged("Email");
//Here's the magic
LoginCommand.RaiseCanExecuteChanged();
}
}
private string _password = null;
public string Password
{
get
{
return _password;
}
set
{
_password = value;
OnPropertyChanged("Password");
//Here's the magic
LoginCommand.RaiseCanExecuteChanged();
}
}
public string mac;
#endregion
public LoginViewModel()
{
wa = new WifiAP();
LoginCommand = new DelegateCommand(Login, CanLogin);
}
public bool CanLogin()
{
return !string.IsNullOrEmpty(Email);
}
public void Login()
{
//
}
#region auxiliaryMethods
public string getMac()
{
mac = wa.GetMACAddress();
return mac;
}
public string hashingMD5(string pass)
{
string pwd = pass;
System.Security.Cryptography.MD5 hs = System.Security.Cryptography.MD5.Create();
byte[] db = hs.ComputeHash(System.Text.Encoding.UTF8.GetBytes(pwd));
string result = Convert.ToBase64String(db);
return result;
}}
MainViewModel
public MainWindowViewModel{
this.AddViewModel(new LoginViewModel() { DisplayName = "Login", InternalName = "LoginViewModel" });
this.AddViewModel(new GeneralViewModel() { DisplayName = "General", InternalName = "GeneralViewModel" });
this.Current_ViewModel = this.GetViewModel("LoginViewModel");
Thanks in advance for your time.