Getting the deafult window

Topics: Prism v4 - WPF 4
Nov 18, 2012 at 7:45 AM
Edited Nov 18, 2012 at 1:53 PM

What I want is getting a custom window from a module or Custom type asssembly to be set as my default window.

I did a sample project here which would describe the issue,

Here I used a Custom Ribbon Window.

I want to know what should I change here :

http://sdrv.ms/SWkOmh

Developer
Nov 19, 2012 at 6:15 PM

Hi,

Based on my understanding defining the default window in a module may not be a recommended approach as by default the Prism initialization process initializes the shell before initializing the modules (Chapter 2: Initializing Prism Applications), in which case this will cause a timing issue if your modules are loosely coupled as you won't be able to resolve the window until the corresponding module is initialized.

On the other hand, in the sample you posted this scenario could be only possible because your main project has a reference to your modules' project, hence this will allow you to register and resolve the window before initializing the modules. The problem with this approach is that any other module you have will be dependent of this module, in which case defining this window in the main project makes more sense.

Also, one thing I notice in your application is that the bootstrapper.run method is not being called in your App.Xaml file, which will be required to start the initialization process. For example you App.xaml code behind could look like this:

 

public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            Bootstrapper bootstrapper = new BootStrapper();
            bootstrapper.Run();
        }
    }
}

I hope you find this handy,

 

Agustin Adami
http://blogs.southworks.net/aadami

Nov 19, 2012 at 8:06 PM

Thanks really,

I think you covered the mistakes here,

What I was looking for was placing the Ribbon in a module while I want to use a RibbonWindow,

I have looked every possible article or discussions but this wasn't mentioned anywhere.

Should I really define any tab in a related module or can I have all in one place (Module or Assembly or ...)

Main Concerns and goals :

using a RibbonWindow and moving things related to it outside the Shell(Main)

Having all the Tabs defined in one place (Not sure on this, but looking more to have a movable module),

great Xaml and Design-Time support.

please answer this if you got mine idea and could complete it.

thanks again ...

Developer
Nov 22, 2012 at 7:11 PM

Hi,

As Agustin mentioned, the window you will use as the Shell window should be placed in the main project (or Shell project) of your application. In your case, you will need to place your RibbonWindow in the main project in order to use it as the shell. However, any other "thing" related to this RibbonWindow could be moved to a module, depending if that "thing" is required by the RibbonWindow at the time of its construction or not. For example, if the RibbonWindow is resolved through dependency injection, all of its dependencies should be in the Shell project too.

Regarding the Tabs (I assume you mean the RibbonTabs), I believe they could be defined in any place you want. You could define them all in the Shell project or in a Module, or distribute them across different Modules. Where to define them will depend mostly on which components should interact with them and the requirements of your scenario along with your personal preferences. Also, depending on where you define them, you will need to take into account how you will add them to the RibbonWindow. For example, you could use a shared service to add the RibbonTabs to the RibbonWindow. Another approach could be to define Regions in the RibbonWindow where you could inject your Ribbons as if they were views, however take into account that Prism does not provide a RegionAdapter for Ribbons, so you will need to create your custom RegionAdapter for them.

Finally, regarding the design time support, take into account that due to how Visual Studio's designer works, any visual component defined in a loosely coupled Module will not be available in the Shell project during design time and vice versa.

Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini