Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I have a WPF window and Multiple controls on the window say, 4buttons, labels, 2 listboxes etc. when the MAximize the window, the size and positions of the controls are not resizing.

How can i make all the controls to adjust position and resize when the window is maximized.

Plz help me out.
Posted
Comments
Simon Bang Terkildsen 22-Aug-11 3:48am    
post your xaml..
Philippe Mori 3-Sep-11 20:18pm    
It is super easy to do in the designer... at least in Visual Studio 2010. You just have to click on appropriate handles to anchor the size of your controls. You can click near the border of the control to add rows or columns if desired (when using default initial container which ios a grid is I remember well).

I will suggest that you use Viewbox as your parent Layout Container which automatically re-size all contents. You can do this by just wrapping all controls inside the Viewbox like:

XML
<Window
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	......
	x:Class="ChartTesting.MainPage"
	Width="640" Height="480">

   <Viewbox>
      <Grid>
      ......
      <Grid>
   </Viewbox>

</Window>
 
Share this answer
 
Comments
ShivendraNirmalkar 8-Aug-13 2:40am    
This code change only size of grid not size of controls.
You might need to use grid layout or other to make the controls fluid in Design. To add controls to the grid layout panel just put the declaration between the opening and closing tags of the Grid. Keep in mind that the row- and columndefinitions must precced any definition of child controls.
The grid layout panel provides the two attached properties Grid.Column and Grid.Row to define the location of the control. As an Example you might try with the following given code. If you count in terms of percentage you just remember that 100% means 1. So if you have 3 controls and you want to put it in three column then you might design its width as .33* for all


XML
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="28" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="200" />
    </Grid.ColumnDefinitions>
    <Label Grid.Row="0" Grid.Column="0" Content="Name:"/>
    <Label Grid.Row="1" Grid.Column="0" Content="E-Mail:"/>
    <Label Grid.Row="2" Grid.Column="0" Content="Comment:"/>
    <TextBox Grid.Column="1" Grid.Row="0" Margin="3" />
    <TextBox Grid.Column="1" Grid.Row="1" Margin="3" />
    <TextBox Grid.Column="1" Grid.Row="2" Margin="3" />
    <Button Grid.Column="1" Grid.Row="3" HorizontalAlignment="Right"
            MinWidth="80" Margin="3" Content="Send"  />
</Grid>
 
Share this answer
 
v2
Comments
Md. Rashim Uddin 24-Aug-11 8:04am    
Did u solve your problem???

Thanks,
Rashim
ShivendraNirmalkar 8-Aug-13 2:40am    
Nothing is change,no variation.
Md. Rashim Uddin 8-Sep-11 2:15am    
Did u try with that??
HTML
<div>
</div>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900