Binding Converter and multibinding

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.

Answers


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>

Need Your Help

jQuery - Replace main image source with dynamic image source

javascript jquery foreach src jquery-hover

I have a list of images showing and each image got a list of 1 or more additional thumbnail images.

pwm value not changing

avr pwm

I have written a pwm code for Atmega128. I am using fast pwm mode with non-inverting pulse on compare match and I need to change the OCR0 value at certain times. Yet it doesn't change. Anyone knows...