Reputation: 445
I want to create 4 rectangles stacked to one row.
|----|--|------|------------|
The width of every rectangle is binded to value in %.
I decided to group rectangles to horizontal StackPanel. To calculate the width of the rectangle I want to write convertor.
What I don't know is how to create converter that must be binded to: - value in % I want to pass the width of parent to converter parameter.
How to write parameter to bind it to parent's width?
Thank you for your answers.
Upvotes: 0
Views: 734
Reputation: 50028
Get rid of the StackPanel and put a Grid with one row and 4 column, That will do the trick. You can resize the control and it will behave properly. Bellow code the ColumnDefinition Width is actually a Percentage value. for example the first rectangle bellow takes 20% of the total width because the ColumnDefinition set 0.2* on that column.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.2*"/>
<ColumnDefinition Width="0.1*"/>
<ColumnDefinition Width="0.25*"/>
<ColumnDefinition Width="0.45*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Rectangle Grid.Column="0" Fill="Black" Stroke="White" StrokeThickness="1"/>
<Rectangle Grid.Column="1" Fill="Black" Stroke="White" StrokeThickness="1"/>
<Rectangle Grid.Column="2" Fill="Black" Stroke="White" StrokeThickness="1"/>
<Rectangle Grid.Column="3" Fill="Black" Stroke="White" StrokeThickness="1"/>
</Grid>
Upvotes: 2