just try using the HorizontalContentAlignment property to "stretch" ListBoxItems using the style
<Style TargetType="{x:Type ListBoxItem}" > <Setter Property="HorizontalContentAlignment" Value="Stretch" /> </Style>
and also turn off the visibility of the HorizontalScrollBar
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Update
<Window.Resources> <SolidColorBrush x:Key="blackBackground" Color="Black"/> <Style TargetType="{x:Type ListBoxItem}" > <Setter Property="HorizontalContentAlignment" Value="Stretch" /> </Style> </Window.Resources> <Grid> <ListBox Grid.Row=" 1" HorizontalContentAlignment="Stretch" Background="#24221f" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding Messages}" ScrollViewer.VerticalScrollBarVisibility="Visible" ClipToBounds="False" BorderBrush="{x:Null}"> <ListBox.ItemTemplate> <DataTemplate > <Border BorderBrush="#24221f" BorderThickness="3" Width=" auto"> <DockPanel Background="{StaticResource blackBackground}" HorizontalAlignment="Stretch" Width="auto"> <Border BorderThickness="3" BorderBrush="Transparent"> <Image Source="{Binding IconImageUrl}" VerticalAlignment="top" Height="22" Width ="22" DockPanel.Dock="Left" /> </Border> <Border BorderThickness="3" BorderBrush="LightGray" Height="auto" Width="auto" HorizontalAlignment="Left" VerticalAlignment="Center" DockPanel.Dock="Left"> <Image Source="{Binding ProfileImageUrl}" VerticalAlignment="Top" HorizontalAlignment="Left" Height="48" Width ="48" /> </Border> <StackPanel Orientation="Vertical" DockPanel.Dock="Left" Margin="5,0,0,0"> <Label Content="{Binding Path=Sender}" Foreground="#feb41c" FontFamily="Verdana" FontWeight="Bold" FontSize="14" /> <TextBlock Text="{Binding Path=ShortMessage}" Margin="10,0,0,0" Foreground="BlanchedAlmond" TextWrapping="Wrap" FontFamily="Verdana" /> <Label Content="{Binding Path=Time}" Margin="10,0,0,0" Foreground="DarkGray" FontFamily="Verdana" FontStyle="Italic"/> </StackPanel> </DockPanel> </Border> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid>
source share