我有一個顯示消息的WPF列表框。它包含左側的頭像和垂直堆疊在頭像右側的用戶名和消息。佈局很好,直到消息文本應該換行,但是我在列表框上得到了一個水平滾動條。強制TextBlock包裝在WPF列表框中
我谷歌搜索並找到類似問題的解決方案,但他們都沒有工作。
<ListBox HorizontalContentAlignment="Stretch" ItemsSource="{Binding Path=FriendsTimeline}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Border BorderBrush="DarkBlue" BorderThickness="3" CornerRadius="2" Margin="3" >
<Image Height="32" Width="32" Source="{Binding Path=User.ProfileImageUrl}"/>
</Border>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Path=User.UserName}"/>
<TextBlock Text="{Binding Path=Text}" TextWrapping="WrapWithOverflow"/> <!-- This is the textblock I'm having issues with. -->
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我認爲你需要將ScrollViewer.HorizontalScrollBarVisibility設置爲「Disabled」而不是「Hidden」 - 否則ListBox仍然會嘗試水平滾動,只是不會看到滾動條。 – 2008-12-29 08:03:18