Search code examples
windows-phone-7expression-blend

Expression blend -- make a control repeat in a rectangular pattern


I've built a button in Blend. Now I want to make a grid of my buttons -- say 4 across and 5 high. How can I do that?


Solution

  • There are a few possibilities.

    1) If your grid is always 4x5 you could use a regular grid. Something like this:

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="0.2*"/>
            <RowDefinition Height="0.2*"/>
            <RowDefinition Height="0.2*"/>
            <RowDefinition Height="0.2*"/>
            <RowDefinition Height="0.2*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.25*"/>
            <ColumnDefinition Width="0.25*"/>
            <ColumnDefinition Width="0.25*"/>
            <ColumnDefinition Width="0.25*"/>
        </Grid.ColumnDefinitions>
        <Button Content="Button" />             
        <Button Content="Button" Grid.Column="2"  Grid.Row="0"/>
        <Button Content="Button" Grid.Column="1" Grid.Row="1" />
    </Grid>
    

    2) The Silverlight for Windows Phone Toolkit contains a WarpPanel. You can give items in the WrapPanel a width and height and they're stacked together, like a 2D stackpanel. If the width of the wrappanel is changed, so are the amount of items on a row.