Enable a button in MVVM

Eduardo Gomez 4,316 Reputation points
2021-06-16T01:29:51.797+00:00

Hello Microsoft

I Manege to disable and enable the button on Register, but I want to do the same with Login

VM

[AddINotifyPropertyChangedInterface]
public class LoginViewModel {
public ICommand OpenPopupCommand { get; set; }
public Command Register { get; set; }
public Command Login { get; set; }
public bool DisplayPopUp { get; set; }
public User User { get; set; }
public bool RegisterAllowed { get; set; }
public bool LoginAllowed { get; set; }

    public LoginViewModel() {
        User = new User {
            OnAnyOfMyPropertiesChanged = () => Register.ChangeCanExecute()
        };
        OpenPopupCommand = new Command(() => {
            DisplayPopUp = true;
        });
        Register = new Command(
            execute: () => {
                Debug.WriteLine(User);
            },
            canExecute: () => {
                RegisterAllowed = User != null
                && !string.IsNullOrEmpty(User.Email)
                && !string.IsNullOrEmpty(User.Password)
                && User.Password.Equals(User.ConfirmPassword);
                return RegisterAllowed;
            });
        Login = new Command(
            execute: () => {
                Debug.WriteLine(User);
            },
            canExecute: () => {
                LoginAllowed = User != null
                && !string.IsNullOrEmpty(User.Email)
                && !string.IsNullOrEmpty(User.Password);
                return RegisterAllowed;
            });
    }
}

}

Developer technologies | .NET | Xamarin
0 comments No comments

1 answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    4 deleted comments

    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.