- 园子里比较好的系列:七篇文章
- 英文学习资料:下载了几篇已打包
- 官网:http://reactiveui.net/
- github:https://github.com/reactiveui
RX实战
先看效果(当密码与确认密码相同时,button自动Abled,不满足条件Enabled):
前端XAML代码很一般:
xaml
<Grid x:Name="LayoutRoot" Background="White"> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="90*" /> <ColumnDefinition Width="160*" /> </Grid.ColumnDefinitions> <TextBlock Text="请输入密码:" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="15" /> <TextBox Width="150" Height="30" Grid.Column="1" HorizontalAlignment="Left" Text="{Binding Password,Mode=TwoWay}"> <i:Interaction.Behaviors> <Behaviors:TextBoxUpdatedBehavior> </Behaviors:TextBoxUpdatedBehavior> </i:Interaction.Behaviors> </TextBox> <TextBlock Text="请确认密码:" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="15" Grid.Row="1" /> <TextBox Width="150" Height="30" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Text="{Binding ConfirmPassword,Mode=TwoWay}"> <i:Interaction.Behaviors> <Behaviors:TextBoxUpdatedBehavior> </Behaviors:TextBoxUpdatedBehavior> </i:Interaction.Behaviors> </TextBox> <Button Grid.Row="2" Grid.ColumnSpan="2" HorizontalAlignment="Center" Width="80" Height="30" Content="确认" Command="{Binding OkCommand}"/> </Grid>
ViewModel代码:
public class MainPageViewModel : ReactiveObject { public MainPageViewModel() { OkCommand = new ReactiveCommand(this.WhenAny(x => x.Password,x => x.ConfirmPassword,(password,confirmpassword)=>(password.Value==confirmpassword.Value&&password.Value!=null))); OkCommand.Subscribe(_ => OpenChildWindow()); } #region Property public ReactiveCommand OkCommand { get; set; } [IgnoreDataMember] public string _password; public string Password { get { return _password; } set { this.RaiseAndSetIfChanged(x => x.Password, value); } } [IgnoreDataMember] public string _confirmPassword; public string ConfirmPassword { get { return _confirmPassword; } set { this.RaiseAndSetIfChanged(x => x.ConfirmPassword, value); } } #endregion }