İki TextBoxes (Kullanıcı adı ve Parola) ve bir Giriş düğmesi ile basit bir oturum açma UserControl kodlama yapıyorum. Giriş butonunun sadece kullanıcı adı ve şifre alanları doldurulduğunda etkinleştirilmesini istiyorum. Prism ve MVVM kullanıyorum. LoginViewModel, Login (Oturum Aç) düğmesine bağlı olan LoginCommand adlı bir özellik içerir. ViewModel'imde bir CanLoginExecute() yöntemim var, ancak yalnızca uygulama başladığında ve daha sonra yeniden başlatıldığında tetikleniyor. Bu yüzden Giriş butonu asla aktif değildir. Neyi kaçırıyorum?WPF-Prism CanExecute yöntemi çağrılmadı
<TextBox x:Name="username"
Text="{Binding Path=Username, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
<TextBox x:Name="password"
Text="{Binding Path=Password, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
<Button Content="Login"
cmnd:Click.Command="{Binding LoginCommand}" />
İşte benim ViewModel
class LoginViewModel : IDataErrorInfo, INotifyPropertyChanged
{
public LoginViewModel()
{
this.LoginCommand =
new DelegateCommand<object>(
this.LoginExecute, this.CanLoginExecute);
}
private Boolean CanLoginExecute(object dummyObject)
{
return (string.IsNullOrEmpty(Username) ||
string.IsNullOrEmpty(Password)) ? false : true;
}
private void LoginExecute(object dummyObject)
{
if (CheckCredentials(Username, Password))
{
....
}
}
#region IDataErrorInfo Members
public string Error
{
get { throw new NotImplementedException(); }
}
public string this[string columnName]
{
get
{
string result = null;
if (columnName == "Username")
{
if (string.IsNullOrEmpty(Username))
result = "Please enter a username";
}
else if (columnName == "Password")
{
if (string.IsNullOrEmpty(Password))
result = "Please enter a password";
}
return result;
}
}
#endregion // IDataErrorInfo Members
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion // INotifyPropertyChanged Members
#region Properties
private String _username;
public String Username
{
get { return _username; }
set
{
if (value == _username)
return;
_username = value;
this.OnPropertyChanged("Username");
}
}
private String _password;
public String Password
{
get { return _password; }
set
{
if (value == _password)
return;
_password = value;
this.OnPropertyChanged("Password");
}
}
public ICommand LoginCommand { get; private set; }
#endregion // Properties
}
:, bir şey Prizma özgü Click.Command = mı. Genellikle
Evet, CMND: xmlns: Click.Command = prizma özeldir CMND = "clr-namespace: Microsoft.Practices.Composite.Presentation.Commands; montaj = Microsoft.Practices.Composite.Presentation" kullanıyorum yana Prism's DelegateCommand, bunun uyumlu komut bağlama mekanizması olacağını düşündüm. Düz Command = "{Binding LoginCommand}" da denedim - aynı şekilde çalışıyor. – Naresh