Typically, you'd bind the TextBox.Text
properties to properties on your ViewModel. This way, the values are stored within the ViewModel, not the View, and there is no "getting" of the values required.
class LoginViewModel : BaseViewModel
{
//...
private string userName;
public string UserName
{
get { return this.userName; }
set
{
// Implement with property changed handling for INotifyPropertyChanged
if (!string.Equals(this.userName, value))
{
this.userName = value;
this.RaisePropertyChanged(); // Method to raise the PropertyChanged event in your BaseViewModel class...
}
}
}
// Same for Password...
Then, in your XAML, you'd do something like:
<TextBox Text="{Binding UserName}" HorizontalAlignment="Left" Height="23" Margin="34,62,0,0" Width="154" />
<PasswordBox Text="{Binding Password}" HorizontalAlignment="Left" Height="23" Margin="34,104,0,0" Width="154"/>
At this point, the LoginCommand
can use the local properties directly.