Take the 2-minute tour ×

Let me show you part of my XAML code :

<ListBox Grid.Row="1"  ScrollViewer.HorizontalScrollBarVisibility="Disabled"
         HorizontalAlignment="Stretch" ItemsSource="{Binding}"  Margin="1,1,0,0"
         Name="listBox_Faits"  Width="290"  VerticalAlignment="Stretch"
            <Border  BorderBrush="SlateGray" BorderThickness="0.5" Margin="1,2,1,1"
                     Width="{Binding ElementName=listBox_Faits, Path=Width}">

When too much borders are created (it is linked with an ObservableCollection), a vertical scroll bar appears, and my border doesn't resize on its own. (I would like to see the complete border, I don t want it to be cut at the end)

If anyone has an idea, thanks! Don't hesitate to ask, if you need more information!



share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

You can make ListBoxItem stretch by adding this, and then you can remove the Width binding for the Border

<ListBox ...>
        <Style TargetType="ListBoxItem">
    <!-- ... -->
share|improve this answer
Wow you're right, it works !!! –  Flo Jan 4 '11 at 14:10
You even resolved an older problem I got!!! Thank you very very very very much! Regards, Flo –  Flo Jan 4 '11 at 14:10
@Flo: No problem :) Two in one then, great! –  Fredrik Hedblad Jan 4 '11 at 14:13
add comment

The problem is that you are setting the Width of the Border. This means it will be a fixed size, even if the visible are is smaller than the size of the list item. If you don't set the Border.Width, it will resize to fit within the scroll bar.

share|improve this answer
Hum, when I don't set any size, each border have a different size : it takes the size of the longest sentence in it. I don't know how to make the border fit perfectly in the listbox, without thinking about the size of its content. I thought it was HorizontalAlignement = "Stretch", but it doesn't work. –  Flo Jan 4 '11 at 13:38
add comment

Your Answer


