Prism allows us to have modular and loosely coupled applications, but how do these loosely coupled pieces communicate? That's where Eventing and the EventAggregator come in: they provide communication channels. A way that the separate pieces of the application can safely talk back and forth. Eventing also has extra goodies (thread preference, weak references) that are built on the lessons learned from past technologies (like CAB). All around, it's a great helper for any Silverlight/Prism (or WPF) application.
public class TurnIntoZombieEvent : CompositePresentationEvent<bool>
{
}
public ZombieButton(IEventAggregator aggregator)
{
_aggregator = aggregator;
InitializeComponent();
var zombieEvent = _aggregator.GetEvent<TurnIntoZombieEvent>();
Zombie_Button.Click += (s, e) =>
{
zombieEvent.Publish(true);
};
}
public PersonVM(IBlankSurface surface, IEventAggregator aggregator)
{
_surface = surface;
IsZombie = false;
var zombieEvent = aggregator.GetEvent<TurnIntoZombieEvent>();
zombieEvent.Subscribe(turnIntoZombie);
}
//...
// This method is subscribed by the earlier call:
//zombieEvent.Subscribe(turnIntoZombie);
//...
public void turnIntoZombie(bool zombify)
{
if (zombify == true)
{
turnIntoZombie();
}
}
Video on how to get an application started in Prism. It provides an overview of Modules, Services and Regions.
This video shows how Prism and Unity interact to provide capablities for Dependency Injection and Service Location. It also shows how to use the ModuleCatalog.
Regions are kind of like Master Pages in Silverlight. This video walks you through how to use Regions to break your application's UI up into usable pieces.
How to fire events directly from XAML into the ViewModel. Current thinking holds that this is the best approach for managing complexity and unit testing in an application.
This video describes the concept of a ViewModel, and it does it outside of Prism. If you're interested in MVVM, this is the video that shows you how to do it.