xamarin.formseventaggregatorprism-7

Event Aggregators not publishing in Prism 7.0 for Xamarin Forms


I have recently updated my Xamarin forms application project from Prism 6.3 to Prism 7.0. Everything seems to be working fine except the eventaggregators which get subscribed correctly but don't seem to get published.

Here is a part of my code used

public ConfigureInventoryEventViewModel(IEventAggregator ea, INavigationService navigationService):base(navigationService,ea)

    {
        TappedBackCommand = new DelegateCommand(TappedBack);

        _ea.GetEvent<SetLocationEvent>().Subscribe(SetLocationDropdown,true);
    }

I am publishing the event from a modal page

public ModalPopupViewModel(IEventAggregator ea, INavigationService 
navigationService):base(navigationService,ea)
{
   ItemTappedCommand = new DelegateCommand<string>(ItemTapped);
}



private void ItemTapped(string strItem)
{
    _ea.GetEvent<SetLocationEvent>().Publish();
}

Event class:

public class SetLocationEvent:PubSubEvent
{
}

Please help.

Xamarin Forms version:2.5.0.280555 Prism.forms:7.0.0396

Thanks


Solution

  • I think you forgot this: _ea = ea

    public ConfigureInventoryEventViewModel(IEventAggregator ea, INavigationService navigationService):base(navigationService,ea)
    {
        _ea = ea;
    
        TappedBackCommand = new DelegateCommand(TappedBack);
        _ea.GetEvent<SetLocationEvent>().Subscribe(SetLocationDropdown,true);
    }
    
    public ModalPopupViewModel(IEventAggregator ea, INavigationService navigationService):base(navigationService,ea)
    {
        _ea = ea;
    
        ItemTappedCommand = new DelegateCommand<string>(ItemTapped);
    }