MadProps.MvvmLight

As you've seen from the previous two posts, I've been knee deep in MVVM Light implementing a coroutine system to simplify the calling of "asynchronous" tasks like dialogs. I was keen to rip this code out of Comicster and put it in its own project, so I've done just that.

Introducing MadProps.MvvmLight.

This project will serve as my own "contrib" project to Laurent's MVVM Light Toolkit, starting out with the coroutine stuff.

The major addition in this first release is the ActivityProcessor class, which serves as the "engine" used to process all activities. I've made it a normal class rather than a static one so that it can be injected into your ViewModels as a dependency, and you can construct it with an IMessenger and/or a Dispatcher in case you're managing those yourself.

The ActivityCommand class is still there, but it has an internal constructor only. You create them using an instance of ActivityProcessor as a factory, like this:

var processor = new ActivityProcessor(MessengerInstance);

SayHelloCommand = processor.CreateCommand(SayHello);

SayHello, in this example, might look like this:

IEnumerable<IActivity> SayHello()
{
    Status = "I'm saying hello!";

    yield return new MessageBoxActivity("Why hello there!", "Hello World",
                         System.Windows.MessageBoxButton.OKCancel);

    Status = "I said hello!";
}

There's no RelayActivity class in this release, since Rob pointed out a bug in my earlier code that, when fixed, rendered that class unnecessary.

Hope someone gets some use out of this code. It certainly simplifed some of my methods!

Update

MadProps.MvvmLight now supports .NET 3.5 SP1 and .NET 4 (both compatible with their respective Client Profile frameworks) and Silverlight 3 and 4! Find the package on NuGet and try it out! I haven't had a chance to test the Silverlight version myself, so any feedback would be greatly appreciated.

.net mvvm wpf coroutines
Posted by: Matt Hamilton
Last revised: 20 Apr, 2024 01:09 PM History

Trackbacks

Comments

03 Jan, 2011 04:12 PM @ version 1

VERY nice implementation, Matt - thanks for sharing this with us!

I decided to showcase it for an internal project, so I commented the whole sources for my internal users - if you would like to have a look at the updated sources, drop me a note and I'll send them back to you.

Thanks again Philipp

03 Jan, 2011 07:47 PM @ version 1

Hi Philipp,

That sounds really interesting! Do you have a Mercurial clone of the repository? You could send me a pull request and I could suck your comments into the trunk. Otherwise drop me an email - mabster at madprops.org.

Thanks!

No new comments are allowed on this post.