Whirlwind991
Whirlwind991

Reputation: 495

WPF columns not spanning correctly

I have a group box containing some bound data:

  <Grid Grid.Column="1" Background="#eeeeee" Margin="10,0,0,0" width="250">
        <GroupBox Padding="5" Header="Lists">                            
        <ListBox x:Name="ListBox" BorderBrush="#FFECECEC" ItemsSource="{Binding Lists}" SelectionChanged="Panel_SelectionChanged" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                <Grid>
                <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="auto"/>
                </Grid.ColumnDefinitions>

                    <Grid Grid.Column="0" >
                    <TextBlock Text="{Binding Name}" Style="{StaticResource Pan}" HorizontalAlignment="Left" />
                    </Grid>

                    <Grid Grid.Column="1" HorizontalAlignment="Right" >
                    <Button Style="{StaticResource Del}" Width="30" Height="30" Margin="5,0,0,0">
                    <Image Source="../Resources/Delete2.png" Width="32" />
                    </Button>
                    </Grid>

                </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        </GroupBox>
    </Grid>

The issue is that the two columns containing the text box and delete button arn't spanning correctly. Check out the screenshot:

enter image description here

Upvotes: 0

Views: 28

Answers (1)

kurakura88
kurakura88

Reputation: 2305

Add this property to your ListBox

HorizontalContentAlignment="Stretch"

Upvotes: 1

Related Questions