ボタンを押すと、2 つの Texbox の値を取得しようとしています (ログイン ウィンドウをシミュレートしています)。ボタンに割り当てられたコマンドは正しく起動しますが、「ログイン」を行うためのテキストボックスの値を取得する方法がわかりません。
これは私のビューモデルです:
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}"/>
誰かが助けてくれたら...私は無限に感謝します.