简体   繁体   中英

Prism5 + Unity, how to raise popup after shell and all modules loaded

I have issue: popup with injected services should be raised after moment when shell loaded, its something like login form, so i raise it on "Loaded" event on shell.

<i:EventTrigger EventName="Loaded">
    <interactivity:InvokeCommandAction Command="{Binding OnShellLoadedCommand}"/>
</i:EventTrigger>

It happens after CreateShell() in Bootstrapper

 protected override DependencyObject CreateShell()
 {
     return Container.Resolve<Shell>();
 }

With prism`s services all right, but problem occured with shared services, because modules load after CreateShell() and i get exception. What is the good plactise how to raise popup after shell loaded?

You need to rethink how you are showing your login screen. If your service exists in a module, obviously you can't create and use it until it has been loaded and registered with the container. So you have a couple of options. Move your login popup into a view in your module, and place the trigger on that view that you use RegisterViewWithRegion in the IModule show/initialize. Then use that view's loaded event. I would actually showing your login dialog before the shell is actually shown. If the login is successful, show the Shell, if it fails you can close the app. Either way, you cannot use a service that hasn't been loaded. So move your login popup to the module that contains the service, or move you login service into the shell so it can be used when the shell is loaded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM