Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting size of wpf/caliburn.micro app while allowing content to resize with main window.

I can't figure out how to control the size of my application while allowing the content to resize with the main window. It is an WPF app and I am using Caliburn Micro (ViewModel first) and all my views are UserControls.

I want the main view UserControl (basically a grid that contains other user controls with their own view models) to stretch and fill out the whole application main window area. So i have set HorizontalAlignment and VerticalAlignment on the main view to Stretch. But this doesn't work as i want.

If i set Height & Width on the main view to some value, then this allows me to control the size of the application main window, but the view will be fixed size and wont resize with main window.

If i set Height & Width on the main view to Auto, then the application window size will adjust to the size of the main view, not the other way around.

What i want is that the content of the application window (the window is automatically created by Caliburn.Micro for the main view) stretches to fill out the application window, the size of which I have set in some way i cant figure out how to do.

Hope you can help, i am stuck!

like image 718
Liell Avatar asked Aug 28 '12 12:08

Liell


1 Answers

I realize this question is very old and probably refers to Caliburn.Micro v1, but just in case someone else like me comes along, here is the solution for Caliburn.Micro v2.

In your Bootstrapper's OnStartup function, you just need to set Width, Height and SizeToContent.Manual settings into the DisplayRootViewFor function as done below:

protected override void OnStartup(object sender, StartupEventArgs e)
{
   var settings = new Dictionary<string, object>
   {
       { "SizeToContent", SizeToContent.Manual },
       { "Height" , 600  },
       { "Width"  , 1024 },
   };

   DisplayRootViewFor<IShell>(settings);
}
like image 196
fireforge124 Avatar answered Oct 30 '22 19:10

fireforge124