Jason94
Jason94

Reputation: 13620

How can i make listitem 100% width?

I have some usercontrols that I want to put in a list:

        <ListBox HorizontalContentAlignment="Stretch">
            <StackPanel x:Name="audioList" />
        </ListBox>

but by some reason they I'm not allowed to put the width to 100%. It does not look good, I want 100% width but not by setting it specifically to some pixel as that would break other device screen resolutions (?)

Upvotes: 1

Views: 350

Answers (1)

ColinE
ColinE

Reputation: 70160

Each item within your list box is hosted within a container. You need to stretch the container as follows:

<ListBox.ItemContainerStyle> 
    <Style TargetType="ListBoxItem"> 
        <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter> 
    </Style> 
</ListBox.ItemContainerStyle>

Upvotes: 4

Related Questions