Search code examples
c#.netwpfprismribbon

prism tabbed content and the ribbons


I'm developing a prism application with a ribbon bar on the top, a outlookbar on the left and a tabbed content region (tabcontrol with regionadapter).

I'm using the view injection.

My problem now is: how to inject the tabitem's own tabcontrol (e.g. edituser button) into the ribbon when switching from one existing tabitem to another one.

I think INavigationAware is not working in this scenario. (right?)

The only approach I could imagine is to hook into the tabheader and do stuff there.

I'm glad of every solution you could give me.

Thanks in advance


Solution

  • I read your response to my question and think Prism's EventAggregator can help you. It's designed to faciliate inter-module communication, among other functions as well. Here's a sample of how you can use it:

    Get an instance of the EventAggregator. I'm using dependenct injection here:

    // Ctor injection
    private IEventAggregator _eventAggregator;
    public YourViewModel(IEventAggregator eventAggregator)
    {
        _eventAggregator = eventAggregator;
    }
    

    Create an event to publish (parameter is for a payload). In your case a tab selection:

    public class TabSelectedEvent:CompositePresentationEvent<object>{}
    

    Publish the event when a tab is selected;

    _eventAggregator.GetEvent<TabSelectedEvent>().Publish(null);
    

    Finally, subscribe to the event and respond:

    _eventAggregator.GetEvent<TabSelectedEvent>().Subscribe(OnTabSelectedEvent);
    

    Now, you should be good to go.