I have a text box and a button that's bound to a property in my view model as follows
<TextBox Text="{Binding UserName, Mode=TwoWay}" />
<Button Content="Log In" Command="{Binding LoginCommand}"/>
My UserName property:
private string userName;
public string UserName
{
get
{
return this.userName;
}
set
{
SetProperty(ref userName, value);
((DelegateCommand)(this.LoginCommand)).RaiseCanExecuteChanged();
}
}
The login command:
LoginCommand = new DelegateCommand(User_Login, Can_Login);
and the Can_Login method:
private bool Can_Login(object arg)
{
if (!string.IsNullOrEmpty(UserName))
return true;
return false;
}
My problem is that login button is always enabled untill the user name text box is not empty and has lost focus.
What I want to do is to make the button become enabled once the user types some text in the TextBox instantly without having the TextBox to lose focus.
is there a workaround for this ?