6
votes

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!

2

2 Answers

11
votes

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);
}
0
votes

Remove the height and width that you have set for yr child controls & use the UIElement.CliptoBounds Property and set it to True.

http://msdn.microsoft.com/en-us/library/system.windows.uielement.cliptobounds.aspx