当我按下按钮时,我试图获取两个 Texboxes 的值(我正在模拟登录窗口)。按钮中分配的命令正确触发,但我不知道如何获取文本框的值来执行“登录”。
这是我的视图模型:
class LoginViewModel : BaseViewModel
{
public LoginViewModel()
{
}
private DelegateCommand loginCommand;
public ICommand LoginCommand
{
get
{
if (loginCommand == null)
loginCommand = new DelegateCommand(new Action(LoginExecuted),
new Func<bool>(LoginCanExecute));
return loginCommand;
}
}
public bool LoginCanExecute()
{
//Basic strings validation...
return true;
}
public void LoginExecuted()
{
//Do the validation with the Database.
System.Windows.MessageBox.Show("OK");
}
}
这是视图:
<Grid DataContext="{StaticResource LoginViewModel}">
<TextBox x:Name="LoginTxtBox" HorizontalAlignment="Left" Height="23" Margin="34,62,0,0" Width="154" />
<PasswordBox x:Name="PasswordTxtBox" HorizontalAlignment="Left" Height="23" Margin="34,104,0,0" Width="154"/>
<Button x:Name="btnAccept"
HorizontalAlignment="Left"
Margin="34,153,0,0"
Width="108"
Content="{DynamicResource acceptBtn}" Height="31" BorderThickness="3"
Command="{Binding LoginCommand}"/>
如果有人可以提供帮助...我将不胜感激。