Skip to content

Instantly share code, notes, and snippets.

@angelobelchior
Created March 15, 2017 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelobelchior/473c50652d07ff967d7dfa37594a5a44 to your computer and use it in GitHub Desktop.
Save angelobelchior/473c50652d07ff967d7dfa37594a5a44 to your computer and use it in GitHub Desktop.
//Esse código é apenas para demonstração da funcionalidade do ChangeCanExecute
public class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void Notify(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public class ViewModel : ViewModelBase
{
string username;
public string Username
{
get
{
return username;
}
set
{
username = value;
Notify("Username");
this.LoginCommand.ChangeCanExecute();
}
}
string password;
public string Password
{
get
{
return password;
}
set
{
password = value;
Notify("Password");
this.LoginCommand.ChangeCanExecute();
}
}
public Command LoginCommand
{
get;
set;
}
public ViewModel ()
{
this.LoginCommand = new Command(this.Excetute, this.CanExecute);
}
private void Excetute(object obj)
{
//efetua login
}
private bool CanExecute(object obj)
{
return !string.IsNullOrEmpty(this.Password) &&
!string.IsNullOrEmpty(this.Username);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment