这就是我想要的:A ListBox
,其项目由 aStackPanel
和两个TextBlock
s 组成。文本块需要支持换行,列表框不应该展开,并且不应该有水平滚动条。这是我到目前为止的代码。将其复制并粘贴到 XamlPad 中,您将看到我在说什么:
<ListBox Height="300" Width="300" x:Name="tvShows">
<ListBox.Items>
<ListBoxItem>
<StackPanel>
<TextBlock Width="{Binding ElementName=tvShows, Path=ActualWidth}" TextWrapping="Wrap">Lost is an American live-action television series. It follows the lives of plane crash survivors on a mysterious tropical island.</TextBlock>
<TextBlock Width="{Binding ElementName=tvShows, Path=ActualWidth}" TextWrapping="Wrap">Lost is an American live-action television series. It follows the lives of plane crash survivors on a mysterious tropical island.</TextBlock>
</StackPanel>
</ListBoxItem>
<ListBoxItem>
<StackPanel>
<TextBlock Width="{Binding ElementName=tvShows, Path=ActualWidth}" TextWrapping="Wrap">Lost is an American live-action television series. It follows the lives of plane crash survivors on a mysterious tropical island.</TextBlock>
<TextBlock Width="{Binding ElementName=tvShows, Path=ActualWidth}" TextWrapping="Wrap">Lost is an American live-action television series. It follows the lives of plane crash survivors on a mysterious tropical island.</TextBlock>
</StackPanel>
</ListBoxItem>
</ListBox.Items>
</ListBox>
这似乎可以防止文本块增长,但有一个问题。文本块似乎比列表框稍大,导致出现水平滚动条。这很奇怪,因为它们的宽度绑定到 lisbox 的 ActualWidth。此外,如果向列表框添加更多项目(只是在 XamlPad 中剪切和粘贴)导致垂直滚动条出现,则文本块的宽度不会调整为垂直滚动条。
如何将 s 保留在TextBlock
s 中ListBox
,有或没有垂直滚动条?