Binder converter and stranded

I want to create 4 rectangles stacked on one line.

| ---- | - | ------ | ------------ |

The width of each rectangle is anchored to a% value.

I decided to group the rectangles into a horizontal StackPanel. To calculate the width of a rectangle, I want to write a transformer.

I don't know how to create a converter that needs to be bound to: - value in% I want to pass the width of the parent element to the converter parameter.

How do I write the parameter to bind to the parent width?

Thank you for your responses.

0


source to share


1 answer


Get rid of the StackPanel and put a Grid with one row and 4 column, which will do the trick. You can resize the control and it will behave correctly. Bellow code the ColumnDefinition Width is actually a percentage value. for example, the first rectangle is below 20% of the total width, because 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>

      

+2


source







All Articles