Mvvm 当文本框失去焦点时,ReactiveUI RaiseAndSetIfChanged hit
我正在使用ReactiveCommand:Mvvm 当文本框失去焦点时,ReactiveUI RaiseAndSetIfChanged hit,mvvm,reactiveui,Mvvm,Reactiveui,我正在使用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 _ => {
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));
});
以及用于绑定的用户名、密码字段:
public string Password
{
get { return _password; }
set { this.RaiseAndSetIfChanged(ref _password, value); }
}
和此绑定的文本框到:
<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"/>
这段代码可以工作,但当我失去对文本框的关注时。当我开始用reactiveUI在文本框上写东西时,有没有合适的方法可以做到这一点。使用UpdateSourceTrigger属性。顾名思义,这意味着每当TextBox的Text属性发生更改时,就会触发RaiseAndSetIfChanged
<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"/>
使用UpdateSourceTrigger属性。顾名思义,这意味着每当TextBox的Text属性发生更改时,就会触发RaiseAndSetIfChanged
<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"/>
使用UpdateSourceTrigger属性。顾名思义,这意味着每当TextBox的Text属性发生更改时,就会触发RaiseAndSetIfChanged
<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"/>
使用UpdateSourceTrigger属性。顾名思义,这意味着每当TextBox的Text属性发生更改时,就会触发RaiseAndSetIfChanged
<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"/>