Gotcha: Huge Window Sizes in Caliburn Micro

If you bind a grid to a large data set, you will inevitably create a control larger than is comfortable to show on the screen.  By default, if you have this the root view model in Caliburn Micro, you will end up with a window that is so large that it is hard to manipulate on the screen.  This is because, by default, the windows that CM creates are set to size to the control.  If you want to change this behaviour, you will need to change the SizeToContent property of the window to Manual.  To do this, you need to do the following:

First, you need a custom window manager.  If you’re using an IoC container, you can simply register an implementation of IWindowManager.  I recommend subclassing the default WindowManager class.  If not, you can simply override GetInstance in the Bootstrapper; this also has to advantage of suppressing annoying on-boot exceptions.

Secondly, override EnsureWindow (as of 1.1, it’s slightly different in 1.0) in the window manager.  You’ll note the window manager is aware of the view model it contains, which allows for more customized approaches depending on your requirements.  A final gotcha: whereas most of the code is found in the Silverlight implementation, WindowManager is completely different between WP7, WPF and Silverlight and is contained in different projects.

Technorati Tags:

Published by

Julian Birch

Full time dad, does a bit of coding on the side.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s