Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

[PRISM] IEventAggregator with a contentView

$
0
0

Hi,

I got a problem using Prism and IEventAggregator.

I have a Content Page register in my app :

containerRegistry.RegisterForNavigation<FicheSMUR>();

In my FicheSMURViewModel, I have an IEventAggregator : (partial code)

private IEventAggregator _ea;
public FicheSMURViewModel(IEventAggregator ea) 
    {
        _ea = ea;
}

So far, so good. But in this same ContentPage, I have a ContentView bind. I want to publish an event from my ContentPage and receive it in my contentView. So I do like follow : (partial code)

private IEventAggregator _ea;

private ContentView _pageContent;
    public ContentView PageContent
    {
        get { return _pageContent; }
        set { SetProperty(ref _pageContent, value); }
    }

public FicheSMURViewModel(IEventAggregator ea) 
    {
        _ea = ea;
    PageContent = new PatientTab();
}

public void OnNavigatingTo(NavigationParameters parameters)
    {
        _ea.GetEvent<FicheChangedEvent>().Publish((string)parameters["ficheName"]);
    }

And in my PatientTabViewModel : (partial code)

public PatientTabViewModel(IEventAggregator ea) 
    {
        ea.GetEvent<FicheChangedEvent>().Subscribe(FicheChanged);
}

private void FicheChanged(string Title)
    {
        //TODO: 
    }

But then I crash on execution, seems like Unity can't find IEventAggregator in PatientTab.
Am I doing something wrong ?

Thanks


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>