views:

308

answers:

2

Im building a wpf app with the composite application block ("prism") V2, and Im having an issue where a user control that is injected by a module is very slow in rendering. The user control contains a datagrid with some 2000 rows in it and there is considerable lag in the control rendering to the screen. Initially I thought the slowness was due to the wpf toolkit datagrid control itself but this is not the case. When I move the control containing the datagrid (TestControl) out of the external module and into the shell project and load it straight from there the control renders immediately without any problems.

Im using the following code in the implementation of IModule in my module to inject the wpf user control into the shell

 this.regionManager.RegisterViewWithRegion("mainRegion", typeof(TestControl));

Is there performance issues when loading controls from other modules in a prism app? Whats the most optimal way to load them in?

Thanks

+1  A: 

It's likely this is an artifact of the lifecycle events. Your shell is going to display well before your modules start to load and register themselves. If you do this it will "appear" to take longer because your UI will appear with a big fat hole in it until the module initialization code fires.

A lot of the samples have you doing something like "Shell.Show();" in your CreateShell method of your bootstrapper, but you might consider moving the references to the Shell to a private member of your bootstrapper class and calling .Show() on it in, like this:

public class Boostrapper : UnityBootstrapper
{
    Shell shell;
    protected override DependencyObject CreateShell()
    {
        shell = Container.Resolve<Shell>();
        return shell;
    }

    protected override void InitializeModules()
    {
        base.InitializeModules();
        shell.Show();

    }

I tried this just now and it definitely felt like my app got a performance boost, so I think I'll make this change myself.

If your modules take a really long time to load, you also might want to show a splash screen between CreateShell and after InitializeModules.

Anderson Imes
+1  A: 

the problem here seemed to be wpf being slow to update when the UI is being updated vai the dispatcher from a background thread. I took up the conversation on codeplex and got it more or less sorted.

http://compositewpf.codeplex.com/Thread/View.aspx?ThreadId=64113

Dav Evans