C#C
C#3y ago
DaVinki

❔ WPF TextBlock colored background no stretching with ListBox HorizontalContentAlignment

This is my XAML code for the list:
        <!-- COM port list -->
        <ListBox Grid.Row="1" Margin="6" HorizontalContentAlignment="Stretch" ItemsSource="{Binding ComPorts}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Background="LightGray" HorizontalAlignment="Center" FontSize="20" Height="30" TextAlignment="Center" FontWeight="Bold" Text="{Binding}"></TextBlock>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>


Here is what the form looks like right now:

I can't get the gray background to extend across the entire list item.
image.png
Was this page helpful?