0

I am trying to create a grid that consists several columns and rows. Inside of some columns and rows there are datagrids. Here is the question: How can i dynamically resize all grids in different columns and rows while I am enlarging the main window? I created all columns and rows like Height="x*" and Width="y*". In other words rows and columns are being resized while the main window is being resized but grids' size remains the same. I want to enlarge all grids and fill the whole column with the grid. I tried to fix grids' size with * and it did not work. Any idea how can i solve this problem ?

Semiru
  • 1
  • 1
  • 1
    Hi, welcome to SO. It would be helpful for folks who want to help see a concept of what you want with some of your code added and/or visuals of some sort to better convey your issue. – Chris W. Jun 25 '14 at 14:43

1 Answers1

0

The default layout behaviour of WPF should give you what you expect.

For example, if you have only this in a Window:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <DataGrid Grid.Row="0" Grid.Column="0" />
</Grid>

The DataGrid should size with the window as you resize it, occupying exactly a quarter of the window in the top left corner.

Be careful that you aren't setting VerticalAlignment or HorizontalAlignment to something other than "Stretch".

If you mean to ask how to size the columns of the DataGrid dynamically, look at this question.

Community
  • 1
  • 1
Andre Luus
  • 3,692
  • 3
  • 33
  • 46
  • 2
    As a side note, `` is the same as `` by default if you want to omit the extra xaml. – Chris W. Jun 25 '14 at 19:15
  • Thank you, problem solved while enlarging window :) But while shrinking it did not help. I had 2 data grids and 1 grid one under another in {row0,column2}. Although i set all elements' alignments to "strech" it didnt work out . As a final solution I defined MinHeight and MinWidth for MainWindow . – Semiru Jun 27 '14 at 12:46
  • Glad you got it sorted. – Andre Luus Jul 11 '14 at 09:41