Search code examples
c#wpfunity-containerprismprism-7

Prism 7. Using PrismApplication.CreateShell() with a non Window control


I would like to update from 6.3 to 7.

I seem to have hit a road block.

When using the PrismApplication class in the App.xaml, CreateShell expects a return type of Window instead of the previous BootStrapper which wanted a DependencyObject.

My MainShell is a modified Telerik RadWindow which itself is a modified System.Windows.Controls.HeaderedContentControl and casting to Window is not possible.

Is there a way around this so I can use the PrismApplication object or do I have to roll back and use the BootStrapper like before?


Solution

  • do I have to roll back and use the BootStrapper like before?

    The bootstrapper is still there. It is marked as deprecated and might go away in a future version, but as long as it's there, you can use it. At least, until the problem with PrismApplicationBase is fixed. You should create an issue on github for that.

    Edit:

    The issue has already been brought up and it won't be fixed (1413).

    I'll copy the proposed workaround from the issue for reference:

    protected override Window CreateShell()
    {
        return null;
    }
    
    protected override void OnInitialized()
    {
        var shellWindow = Container.Resolve<ShellWindow>();
        shellWindow.Show();
        MainWindow = shellWindow.ParentOfType<Window>();
    
        // there lines was not executed because of null Shell - so must duplicate here. Originally called from PrismApplicationBase.Initialize
        RegionManager.SetRegionManager(MainWindow, Container.Resolve<IRegionManager>());
        RegionManager.UpdateRegions();
        InitializeModules();
    
        base.OnInitialized();
    }