I'm working with a WPF ListBox and inside the ItemTemplate I have a StackPanel. I'm trying to bind the width of the StackPanel to the ViewportWidth of the ListBox but I'm not able to find a way to do so. If I bind the ActualWidth it's close, but since the vertical scrollbar is included in the ActualWidth I still end up with things hidden behind it and a horizonal scroll bar.
Please see the XAML below:
<ListBox x:Name="MessagesGrid" Grid.Column="2" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="{Binding Path=ActualWidth, ElementName=MessagesGrid}" HorizontalAlignment="Stretch">
<StackPanel Name="ToMe" HorizontalAlignment="Stretch" Visibility="{Binding IsFromMe, Converter={StaticResource BooleanToHiddenConverter}}">
<TextBlock Text="{Binding Date}" FontSize="8" TextWrapping="Wrap" Padding="0,0,60,0"/>
<TextBlock Text="{Binding Text}" FontSize="12" TextWrapping="Wrap" Padding="0,0,60,0"/>
</StackPanel>
<StackPanel Name="FromMe" HorizontalAlignment="Stretch" Visibility="{Binding IsFromMe, Converter={StaticResource BooleanToVisibleConverter}}">
<TextBlock Text="{Binding Date}" HorizontalAlignment="Right" FontSize="8" TextWrapping="Wrap" Padding="60,0,0,0"/>
<TextBlock Text="{Binding Text}" HorizontalAlignment="Right" FontSize="12" TextWrapping="Wrap" Padding="60,0,0,0"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>