views:

529

answers:

3

I have the below xaml markup, the button does not seen to stretch across the screen instead its left aligned. It is contained in a stack panel. What am I doing wrong here?

    <Grid>
    <ListBox Name="SideNavBar">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Vertical" HorizontalAlignment="Stretch">
                    <Button Content="{Binding}"/>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    </Grid>
A: 

It illogical for a StackPanel to stretch because it's job is to place each child control in a row or a column, side by side.

I think the same thinking applies to ListBox, but I'm unable to confirm at the moment.

BC
A: 

You've set the StackPanel alignment to stretch in your example, not the Button.

TreeUK
A: 

This is apparently a known issue with the ListBoxItem.

See this forum discussion...

Glen Little