Typically, you bind TextBox.Text properties to properties in the ViewModel. Thus, the values are stored in the ViewModel, not in the view, and there is no need to get the values.
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 will 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, LoginCommand can use local properties directly.
source share