0

I am trying to make my listbox to have the same width as the window here is a minimum example.

    <ListBox ItemsSource="{Binding MyList}" Background="Blue">
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Setter Property="HorizontalAlignment" Value="Stretch"/>
            </Style>
        </ListBox.ItemContainerStyle>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid Background="Black" HorizontalAlignment="Stretch">
                    <TextBlock Text="test" HorizontalAlignment="Stretch"/>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

The result looks like

enter image description here

Where the blue part is the list box and the black parts are the rows. I am trying to make the rows to have the same width as the listbox

Community
  • 1
  • 1
Steve
  • 11,696
  • 7
  • 43
  • 81
  • HorizontalContentAlignment="Stretch"? –  Jul 20 '16 at 13:56
  • @Will already tried, no luck. Had horizontal stretch on every single element I can apply it on – Steve Jul 20 '16 at 13:58
  • Set `HorizontalContentAlignment="Stretch"` on the ListBox, not on the ListBoxItem. – Clemens Jul 20 '16 at 13:59
  • Should work. Don't see how it wouldn't. I'd examine the visual tree at runtime either using the xaml debugging tools in 2015 or using Snoop or similar. –  Jul 20 '16 at 14:01
  • If you edit to show a minimal example where you use the HCA property, and show in a screenshot that it isn't working, I'll reopen and add an example where it does. –  Jul 20 '16 at 14:14
  • 1
    @Will setting it on ListBox solved the problem. Thanks – Steve Jul 20 '16 at 14:15

0 Answers0