0

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.

kenny
  • 21,522
  • 8
  • 49
  • 87
Ozan Yurtseven
  • 810
  • 8
  • 17

1 Answers1

3

Use UpdateSourceTrigger property. As the name implies, this means that whenever there is a change in the Text property of TextBox, RaiseAndSetIfChanged fires.

<TextBox x:Name="txtPassword" Text="{Binding Password, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="2" Margin="3,3,0,3" MinWidth="100" HorizontalAlignment="Left" Width="10" Height="30"/>
Abdurrahman Alp Köken
  • 1,236
  • 1
  • 13
  • 12