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

2

6

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!

Burdine answered 28/8, 2012 at 12:21 Comment(0)
O
12

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);
}
Ostyak answered 2/4, 2015 at 15:23 Comment(0)
S
0

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

Schism answered 28/8, 2012 at 12:57 Comment(2)
But that controls how elements are clipped. That is not my main problem here. How do i set the overall startup size of the app while allowing the grid in the main view to resize with the app after startup?Burdine
#36608Schism

© 2022 - 2024 — McMap. All rights reserved.