Resize my border when VerticalScrollBar appears

Let me show you some 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 many borders are created (it is associated with an ObservableCollection), a vertical scrollbar appears, and my border does not change on its own. (I would like to see the full border, I do not want it to be cut at the end)

If anyone has an idea, thanks! Feel free to ask if you need more information!

Rgds,

Flo

+6
c # resize wpf border datatemplate
source share
2 answers

You can do a 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> <!-- ... --> 
+3
source share

The problem is that you are setting the border width. This means that it will be a fixed size, even if the visible size is smaller than the size of the list item. If you do not set Border.Width, the size will be resized to fit the scroll bar.

0
source share

All Articles