Skip to content

Instantly share code, notes, and snippets.

@anaisbetts
Created February 3, 2011 23:10
Show Gist options
  • Save anaisbetts/810428 to your computer and use it in GitHub Desktop.
Save anaisbetts/810428 to your computer and use it in GitHub Desktop.
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