This code can be executed at any time, even when the MainWindow is not visible yet, and there is no visual tree. The MIF queues the injected modules and shows them as soon as the relevant regions are loaded.
There are no injected modules in the Documents region initially.
The DocumentGroup is injected with modules when the user selected one of the modules in the NavBarGroup on the left side.
The Navigation event is used to achieve this kind of navigation.
First, it checks if the selected module exists. Then it uses the **InjectOrNavigate** method to navigate a particular module. The first argument specifies a region in which the navigation is happening. The second argument selects a module.
Note, that the modules registered in the Navigation region have the same keys as the modules registered in the Documents region. This allows to map NavigationItem modules to the corresponding ModuleViewModel modules easily.
InjectOrNavigate is a helper method that combines the functionality of the Inject and Navigate methods. If no module with a particular key has been injected before the invocation of the InjectOrNavigate method, the method first injects the provided module and then navigates it.
The second event handler provides the synchronization functionality: when the user selects a particular tab, the corresponding NavigationItem on the left is selected.
The code example above contains no check for e.NewViewModelKey because the application always displays a selected tab when running. All NavigationItem modules are injected at startup, and there is no need to inject them again inside the handler.
Was this page helpful?
Thanks for your feedback! Any other suggestions? Tell us here.