Created
February 3, 2011 23:10
-
-
Save anaisbetts/810428 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NewUserViewModel : ReactiveObject | |
{ | |
// This is ReactiveUI's version of implementing INotifyPropertyChanged | |
string _Password; | |
public string Password { | |
get { return _Password; } | |
set { this.RaiseAndSetIfChanged(x => x.Password, value); } | |
} | |
string _PasswordConfirmation; | |
public string PasswordConfirmation { | |
get { return _PasswordConfirmation; } | |
set { this.RaiseAndSetIfChanged(x => x.PasswordConfirmation, value); } | |
} | |
ICommand OkCommand { get; protected set; } | |
public NewUserViewModel() | |
{ | |
// Here's the interesting part - we'll combine the change notifications | |
// for Password and PasswordConfirmation, and that will determine when | |
// we can hit the Ok button | |
// | |
// canHitOk is now a stream of True's and False's | |
var canHitOk = this.WhenAny( | |
x => x.Password, | |
x => x.PasswordConfirmation, | |
(pass, confirm) => (pass.Value == confirm.Value && pass.Value.Length > 3)); | |
// Feed this to the canExecute of the OkCommand - now the button is | |
// bound to the two properties and will disable itself until the | |
// Func above is true. | |
OkCommand = new ReactiveCommand(canHitOk); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment