Pass event from host to Prism class library

Topics: Prism v4 - WPF 4
Sep 7, 2011 at 2:58 PM

Hi,

My WPF class library is in prism. This class library contained some tools/buttons that to be place in the host application. Some of the buttons will bring up WPF window/usercontrol which I know how to implement. But other buttons will just fire some event (like mouse click) in the host app and has no UI. And I need to pass the event (and the parameters that associated with the event, like mouse position) into my DataService module (which is already added in bootstrapper). When the button is clicked, the bootsrapper is alreay initialized and configured and ready to use.

Some snipets:

In bootsstrapper:

protected override void ConfigureAggregateCatalog()
{
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(DataServiceIni).Assembly));
}

In my button OnClick:

public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
            // TODO: send OnMouseDown and x,y into the DataService that added in Bootstrapper catalog
}

How to do this?

Thanks!

Developer
Sep 7, 2011 at 3:33 PM

Hi,

Prism does not provide a way to achieve this out-of-the-box; depending on the nature of the host application you're using, you could create a "bridge" service that communicates with the Prism application through, for example, the Event Aggregator. You can probably access the Event Aggregator through the ServiceLocator.Current static property, in case you have already defined the service locator provider in the Bootstrapper (which is done by default in the ConfigureServiceLocator method).

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi