views:

127

answers:

1

The following code works for stretching the child Grid within the ListBoxItem in Silverlight 3, but not in Windows Phone 7. Is this a bug or am I doing something wrong? No matter what element I put in the ListBoxItem, it never grows to the size of the ListBoxItem, only to the size of its own content. My end goal is to get the text to align left and right within the ListBoxItem. In the process of trying to do that, I ran into this issue.

Note: HorizontalContentAlign seems to work fine for values other than Stretch.

<ListBox>
    <ListBoxItem HorizontalContentAlignment="Stretch">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.5*"/>
                <ColumnDefinition Width="0.5*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
            </Grid.RowDefinitions>

            <TextBlock Grid.Row="0" Grid.Column="0">Left text</TextBlock>
            <TextBlock Grid.Row="0" Grid.Column="1" TextAlignment="Right">Right text</TextBlock>
        </Grid>
    </ListBoxItem>
</ListBox>
+1  A: 

Hi CACuzcatlan,

Peter Torr makes reference to a bug in the current release (think he means beta) and offers a workaround. Apparently it's fixed in internal builds already.

Mick N