Content Control Very Slow vs Show Dialog?

Topics: Conventions, Getting Started
Jun 30, 2011 at 1:56 AM

I am new to Caliburn.Micro and may be missing something very basic but I can't figure out how to fix this problem.  I originally intended to show a series of views in the ShellView using a Content Control.  I set up a property in ShellViewModel for another ViewModel

        public BaseCaseViewModel BaseCaseVM         
            get { return _BaseCaseVM; }
            set { _BaseCaseVM = value;
            NotifyOfPropertyChange(() => BaseCaseVM );
In the ShellView, I have the following Xaml:
 <ContentControl x:Name="BaseCaseVM" />
In my BaseCaseViewModel there is a TreeListControl.  Everything populates fine but navigating the tree is extremely slow.  To try to figure out why, I tried loading the BaseCaseViewModel in a ModalDialog and the speed is much much faster (15 sec on click to expand the tree in the Content Control vs 1 sec in the Dialog)
I then decided to render the viewModel twice using both approaches by updating the property and instantiating the dialog:
            BaseCaseVM = new BaseCaseViewModel();
            windowManager.ShowDialog(new BaseCaseViewModel());
Same result.  The Dialog View is significantly faster.
I assume there is something in the Content Control Binding that is creating the extra overhead.  Any ideas on what I'm doing/not doing that is creating this discepancy in performance?
As an aside.  The content control is bounding using the nameing convention,  I know when I bind a grid, I can overide the name convention using the ItemsSource Property.  Which property binds the ViewModel to the ContentControl?
Thanks for your help.


Jul 4, 2011 at 10:21 PM

Conventions bind VMs against cal:View.Model attached property.
Setting this property causes the execution of some CM "magic"  (like locating the corresponding View and applying conventions against the child View).
After that, CM just puts the obtained child View into the ContentControl's Content property; the entire operation is somewhat equivalent to setting the Content property with a ContentTemplate defined.
I also want to point out that the same occurs (even with a slightly different mechanism) when opening a dialog: both View location and View-VM conventional binding are executed as well.

I really can't figure out why you are getting that performance penalty; you are correctly using the standard CM's UI composition technique.
It could perhaps depend on some complex layout/resizing issue (occurring just when the tree is hosted in the shell), or it may be related to a particular treeview binding or styling. It's hard to tell.
From the reported timings (even the fastest one), I guess you have a *very* large tree.

Do you have the chance to build a minimal repro demonstrating the issue? It would greatly help me to investigate it further.