I'm using ReactiveCommand:
LoginCommand = new ReactiveCommand(this.WhenAny(x => x.UserName, x => x.Password, (r, g) => !string.IsNullOrEmpty(r.Value) &&!string.IsNullOrEmpty(g.Value)));
LoginCommand.Subscribe(async _ =>
{
var user = await _authenticationService.AuthenticateUser(_userName, _password);
if (user.Error != null)
{
MessageBox.Show("The user was not found. Please try again!", "User Not Found", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
screen.Router.Navigate.Execute(new MainViewModel(screen));
});
And UserName, Password field for binding:
public string Password
{
get { return _password; }
set { this.RaiseAndSetIfChanged(ref _password, value); }
}
And Textbox for this binding to:
<TextBox x:Name="txtPassword" Text="{Binding Password}" Grid.Column="1" Grid.Row="2" Margin="3,3,0,3" MinWidth="100" HorizontalAlignment="Left" Width="10" Height="30"/>
This code work but when I lose focus on textbox. Is there any proper way to do this when I start writing on textbox with reactiveUI.