ReactiveUI some easy but nice.

23 November 2014

I have been using Paul Bett’s ReactiveUI which is a .NET UI API framework for WPF, Sillverlight, WinForms, Xamarin.Forms, perhaps more. It’s built on top of Microsoft’s system.reactive or Reactive Extensions. I really like how ReactiveUI works, but it can be a mind twist to get started with.

I didn’t find a similar example online, but I have a button in a app that sequences through a list of choices. I thought it would be nice to have it do something once the user has stopped changing the selection. In this example, the button is implemented by ReactiveUIs ReactiveCommand which is it’s wrapper around the stand ICommand for WPF, Silverlight, etc..

public ReactiveCommand<Object> ActionNext { get; set; }

So in this example ActionNext simply sequences through a bunch of choices. Imagine a set of colors as strings, but that list could be anything. The following { CODEHERE; }, will only execute after the user stops clicking on teh ActionNext command for 1 second.

this.WhenAnyObservable( model => model.ActionNext.IsExecuting )
.StartWith( true )
.Throttle( TimeSpan.FromMilliseconds( 1000 ) )
.Subscribe( executing =>
{
if ( ! executing )
{ CODEHERE; }
} );

I think that’s pretty cool. What is happening it ‘Subscribe’s to changes of the RaectiveCommand’s IsExecuting true and back to false. Only when that stops changing aak executing for a 1 second, will the Subscribe code fire.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: