Created
March 15, 2017 00:20
-
-
Save angelobelchior/473c50652d07ff967d7dfa37594a5a44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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