Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize my border when a VerticalScrollBar appear

Let me show you part of my XAML code :

<ListBox Grid.Row="1"  ScrollViewer.HorizontalScrollBarVisibility="Disabled"
         ScrollViewer.IsDeferredScrollingEnabled="True"
         HorizontalAlignment="Stretch" ItemsSource="{Binding}"  Margin="1,1,0,0"
         Name="listBox_Faits"  Width="290"  VerticalAlignment="Stretch"
         SelectionChanged="listBox_Faits_SelectionChanged">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <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!

Rgds,

Flo

like image 524
Flo Avatar asked Jan 04 '11 10:01

Flo


1 Answers

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

<ListBox ...>
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        </Style>
    </ListBox.ItemContainerStyle>
    <!-- ... -->
like image 128
Fredrik Hedblad Avatar answered Oct 16 '22 03:10

Fredrik Hedblad