tmt
tmt

Reputation: 704

synchronise grid columns width in defferent grids, or simplest way to unite cells in some table

I have 3 grids width 3 columns, witch have width="Auto". I want to equate resulting width of the corresponding columns. So i need this rule:

grid[0].column[0].width = grid[1].column[0].width = grid[2].column[0].width

grid[0].column[1].width = grid[1].column[1].width = grid[2].column[1].width

grid[0].column[2].width = grid[1].column[2].width = grid[2].column[2].width

Is it possible in wpf?

Or: is there another way to bild Table, with possability to unite cells( in a vertical, and horisontal), where interface of data is fixed?

thx

Upvotes: 2

Views: 202

Answers (1)

Rachel
Rachel

Reputation: 132548

You can use the Grid.IsSharedSizeScope and SharedSizeGroup properties to make the columns or rows in different Grids share the same width or height

<Grid x:Name="Grid1" Grid.IsSharedSizeScope="True">
  <Grid.ColumnDefinitions>
    <ColumnDefinition SharedSizeGroup="FirstColumn"/>
    <ColumnDefinition SharedSizeGroup="SecondColumn"/>
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>
    <RowDefinition Height="Auto" SharedSizeGroup="FirstRow"/>
  </Grid.RowDefinitions>

  ...

</Grid>

<Grid x:Name="Grid2" Grid.IsSharedSizeScope="True">
  <Grid.ColumnDefinitions>
    <ColumnDefinition SharedSizeGroup="FirstColumn"/>
    <ColumnDefinition SharedSizeGroup="SecondColumn"/>
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>        
    <RowDefinition Height="Auto" SharedSizeGroup="FirstRow"/>
  </Grid.RowDefinitions>

    ...

</Grid>

Upvotes: 1

Related Questions