Shaharyar
Shaharyar

Reputation: 12439

Dynamic Rectangle Height

I have to fill my window with three adjustable Rectangles like:

enter image description here

<Grid x:Name="FileDragAndDrop" Grid.Row="0" Grid.RowSpan="2" Background="Aqua">
     <Rectangle Fill="Beige" HorizontalAlignment="Stretch" Height="110" Stroke="Black" VerticalAlignment="Top" />
     <Rectangle Fill="Aquamarine" HorizontalAlignment="Stretch" Height="110" Stroke="Black" VerticalAlignment="Center" />
     <Rectangle Fill="BlanchedAlmond" HorizontalAlignment="Stretch" Height="110" Stroke="Black" VerticalAlignment="Bottom" />
</Grid>

But the above code does this:

enter image description here

I tried Height="2*" (following the answer) but it gives error

'2*' string cannot be converted to length

How can I resolve this error and make their height dynamic? Is it possible with the xaml or will I have to do it in C#?

Upvotes: 1

Views: 516

Answers (1)

King King
King King

Reputation: 63327

In case you cannot put the rectangles into rows of the main grid, you can use a nested Grid and Grid.RowSpan to cover the nested Grid over the whole main grid.

<Grid x:Name="FileDragAndDrop" Grid.Row="0" Grid.RowSpan="2" Background="Aqua">
  <Grid.RowDefinitions>
      <!-- suppose you have 3 RowDefinitions here -->
  </Grid.RowDefinitions>
  <Grid Grid.RowSpan="3">
     <Grid.RowDefinitions>
         <RowDefinition MinHeight="110"/>
         <RowDefinition MinHeight="110"/>
         <RowDefinition MinHeight="110"/>
     </Grid.RowDefinitions/>
     <Rectangle Fill="Beige" Stroke="Black"/>
     <Rectangle Fill="Aquamarine" Stroke="Black" Grid.Row="1"/>
     <Rectangle Fill="BlanchedAlmond" Stroke="Black" Grid.Row="2"/>
  </Grid>
</Grid>

Upvotes: 1

Related Questions