【发布时间】:2021-05-12 10:53:51
【问题描述】:
我正在使用带有MVVMHelpers 的 MVVM 模式。
我已经制作了登录表单,但我试图仅在用户输入了他的用户名和密码后才启用该按钮。
public ICommand LoginCommand { get; set; }
private string _Username;
public string Username {
get { return _Username; }
set {
if (_Username != value) {
_Username = value;
RaisePropertyChanged();
Activate();
}
}
}
private string _Password;
public string Password {
get { return _Password; }
set {
if (_Password != value) {
_Password = value;
RaisePropertyChanged();
Activate();
}
}
}
private bool _IsEnabled;
public bool IsEnabled {
get { return _IsEnabled; }
set {
if (_IsEnabled != value) {
_IsEnabled = value;
RaisePropertyChanged();
}
}
}
public bool Activate() {
if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)) {
IsEnabled = true;
return true;
}
return false;
}
public LoginVM() {
LoginCommand = new Command(() => {
MessageBox.Show("LogeIn");
});
}
}
如您所见,我通过将类的属性公开给我的 VM 来实现这一点。 我想知道是否有办法在不暴露的情况下做到这一点? https://github.com/eduardoagr?tab=repositories
【问题讨论】: