Problem with EventAggregator

Topics: Prism v4 - Silverlight 4
Sep 8, 2011 at 9:58 PM

Dear all,

recently began to study the Prism. There was a problem with EventAggregator. After subscribing to an event (ea.GetEvent<Events>().Subscribe (eh)) in plugin silverlight library, and after an event is published in Shell.xaml (Method Publish), the event is not generated (is not execute, the error also does not occur). I need to organize the relationship between Shell and the plugin Control. Where am I wrong?

Thank you.


public class Bootstrapper : MefBootstrapper
        protected override IModuleCatalog CreateModuleCatalog()
            return Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(new Uri("/SilverlightApplication1;component/ConfigModules.xaml", UriKind.Relative));

        protected override void ConfigureAggregateCatalog()
            AggregateCatalog.Catalogs.Add(new AssemblyCatalog(this.GetType().Assembly));

        protected override DependencyObject CreateShell()
            return Container.GetExportedValue<Shell>();

        protected override void InitializeShell()
            Application.Current.RootVisual = (Shell)this.Shell;


        ModuleType="SilverlightApplication2.ModuleQuiz, SilverlightApplication2, Version=, Culture=neutral, PublicKeyToken=null" />

Container in Shell.xaml:
  <ContentControl x:Name="MainRegion" prism:RegionManager.RegionName="MainRegion" 
                        VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
        <Button Content="Button" Height="23" Name="button1" Width="75" Click="button1_Click" />

[Export] public partial class Shell : UserControl { public Shell() { InitializeComponent(); } [Import(AllowRecomposition = false)] public IModuleManager ModuleManager; [Import(AllowRecomposition = false)] public IRegionManager RegionManager; [Import] public IEventAggregator ea { get; set; } private void button1_Click(object sender, RoutedEventArgs e) { ea.GetEvent<Events>().Publish("temp string"); }

EventArgs class:

public class Events:CompositePresentationEvent<string>


Plugin side:

Boot plugin:

        public class ModuleQuiz : IModule
            [Import(AllowRecomposition = false)]
            public IRegionManager regionManager;

            public void Initialize()
                this.regionManager.RegisterViewWithRegion("MainRegion", typeof(UC));

Eventargs class on plugin side:

        public class Events : CompositePresentationEvent<string>


Plugin control:

    public partial class UC : UserControl
        public UC(IEventAggregator a)

            this.ea = a;

        public void eh(string str)

        public IEventAggregator ea { get; set; }

* method eh is not executed.

Sep 9, 2011 at 5:38 PM


It is likely that the problem you're experiencing could be related to the fact that you are declaring your Events class twice. The class that inherits from CompositePresentationEvent is responsible for identifying an event (so that when you publish and subcribe events using that class as the type parameter in the GetEvent method, it is clear that you are referring to the same event).

Therefore you could try declaring a unique Events class in an Infrastructure project (which would be referenced in both your shell and your "plugin" modules).

You might find the Prism Training Kit useful, specially the Communication Lab Exercise 2 which shows how to implement Event Aggregator.

Also you will find more information regarding that in the Prism documentation:

I hope you find this useful

Agustin Adami