我有一個綁定到一個屬性在我看來模型的文本框和一個按鈕如下Windows Phone TextBox的提升命令RaiseCanExecuteChanged TextChanged?
<TextBox Text="{Binding UserName, Mode=TwoWay}" />
<Button Content="Log In" Command="{Binding LoginCommand}"/>
我的用戶名屬性:
private string userName;
public string UserName
{
get
{
return this.userName;
}
set
{
SetProperty(ref userName, value);
((DelegateCommand)(this.LoginCommand)).RaiseCanExecuteChanged();
}
}
login命令:
LoginCommand = new DelegateCommand(User_Login, Can_Login);
和Can_Login方法:
private bool Can_Login(object arg)
{
if (!string.IsNullOrEmpty(UserName))
return true;
return false;
}
我的問題是,登錄按鈕始終啓用,直到用戶名文本框不爲空,已失去焦點。
我想要做的是讓用戶一旦在TextBox中立即鍵入一些文本而不讓TextBox失去焦點,就可以啓用該按鈕。
有沒有解決這個問題的方法?
非常感謝,它的工作對我來說,也許包裹在一個自定義的控制這一功能將使它更容易 –