Search code examples
c#wpfprismmef

Cannot raise InteractionRequest in OnNavigatedTo Method?


I'm navigating to a view when its module gets loaded:

public void OnImportsSatisfied()
{
    this.ModuleManager.LoadModuleCompleted +=
            (s, e) =>
            {   
                if (e.ModuleInfo.ModuleName == EmailModuleName)
                {
                    this.RegionManager.RequestNavigate(
                        RegionNames.MainContentRegion,
                        InboxViewUri);
                }
            };
    }

when I navigate to this view I want to raise a NotificationRequest (and his PopupWindow); this method is defined in the ViewModel:

void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
{
    MyInteractionRequest.Raise(...);
}

Through debugging I discovered that the InteractionRequest has no subscribers to its Raised event for the first time I navigate to the view, and that's why no interaction window is shown. In order to make the InteractionRequest work I need to navigate to another view and then go back. Why does this happend? Does the view get created too late after the viewmodel and so it cant subscribe the InteractionTrigger to the Interaction Request?


Solution

  • My guess is that the view has not been initialized by the time you raise the request. This means no bindings have been created and no handlers have been added. You approach in general is bad practice. If you must show a popup when the page is first show, add an event to command behavior for the view's loaded event and show your popup there. This ensures that the pages has been fully loaded and all bindings have been made.