WPF has certain βcontainerβ controls that automatically resize content, and there are some that don't.
Here are some that do not resize the content (I assume you are using one or more of them):
StackPanel WrapPanel Canvas TabControl
Here are some that resize content:
Grid UniformGrid DockPanel
Therefore, it is almost always preferable to use a Grid instead of a StackPanel if you do not want to automatically resize. Note that it is still possible that the Grid does not change its internal controls ... it all depends on your settings for Grid.RowDefinition and Grid.ColumnDefinition :
<Grid> <Grid.RowDefinitions> <RowDefinition Height="100" /> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> </Grid>
For more information about the Grid control, see the Grid Class page on MSDN. You can also learn more about these container controls on the WPF Container Controls Overview page on MSDN.
Further resizing can be achieved using the FrameworkElement.HorizontalAlignment and FrameworkElement.VerticalAlignment properties. The default value for these properties is Stretch , which stretches the elements according to the size of their controls. However, when they are set to any other value, the elements will not stretch.
UPDATE β>
In response to the questions in your comment:
Use the settings of Grid.RowDefinition and Grid.ColumnDefinition to first organize the basic structure ... usually you need to add Grid controls to cells of external Grid controls, if necessary. You can also use the Grid.ColumnSpan and Grid.RowSpan properties to enable controls for placing multiple columns and / or rows of the Grid .
It is most common to have at least one row / column with Height / Width of "*" that will fill the entire remaining space, but you can have two or more with this parameter, in which case the remaining space will be divided between two (or more) rows / columns. "Auto" is a good setting for rows / columns that are not set to "* *", but it really depends on how you want the layout to be.
There are no Auto settings that you can use in the controls in the cells, but it's just as good because we want the Grid determine the sizes of the controls for us ... so we donβt want to set the Height or Width these controls at all.
What I did about the FrameworkElement.HorizontalAlignment and FrameworkElement.VerticalAlignment properties was just to let you know that they exist ... since their default value is already Stretch , you usually don't need to set them explicitly.
The Margin property is usually just used to evenly distribute your controls ... if you drag controls from the Visual Studio Toolbox, VS sets the Margin property to place your control exactly where you reset it, but usually itβs not what we want, as it will be useless with automatic selection of controls. If you do, simply delete or edit the Margin property to suit your needs.