Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VariableSizedWrapGrid and WrapGrid children size measuring

Both VariableSizedWrapGrid and WrapGrid have strange measuring - they measure all children based on the first item.

Because of that, the following XAML will clip the third item.

    <VariableSizedWrapGrid Orientation="Horizontal">
        <Rectangle Width="50" Height="100" Margin="5" Fill="Blue" />
        <Rectangle Width="50" Height="50" Margin="5" Fill="Red" />
        <Rectangle Width="50" Height="150" Margin="5" Fill="Green" />
        <Rectangle Width="50" Height="50" Margin="5" Fill="Red" />
        <Rectangle Width="50" Height="100" Margin="5" Fill="Red" />
    </VariableSizedWrapGrid>

Seems like VariableSizedWrapGrid measures the first item and then the rest children are measured with desired size of the first one.

Any workarounds?

like image 233
sashaeve Avatar asked Jul 23 '12 15:07

sashaeve


1 Answers

You need to use the Attached Properties on each Rectangle VariableSizeWrapGrid.ColumnSpan and VariableSizeWrapGrid.RowSpan as well as add an ItemHeight and ItemWidth to the VariableSizeWrapGrid:

<VariableSizedWrapGrid Orientation="Horizontal" ItemHeight="50" ItemWidth="50"> 
    <Rectangle 
        VariableSizedWrapGrid.ColumnSpan="1" 
        VariableSizedWrapGrid.RowSpan="2"
        Width="50" Height="100" Margin="5" Fill="Blue" /> 
</VariableSizedWrapGrid>
like image 190
Michael S. Scherotter Avatar answered Oct 21 '22 17:10

Michael S. Scherotter