다음은 내가 원했던 것입니다 : 이 TextBlock
인 항목이있는 ListBox
입니다. 텍스트 블록은 줄 바꿈을 지원해야하며 목록 상자는 확장되어서는 안되며 가로 스크롤 막대가 없어야합니다. 지금까지 제가 가지고있는 코드는 다음과 같습니다. 복사 XamlPad에 붙여 넣습니다 그리고 당신은 내가 무슨 말을하는지 볼 수 있습니다 : 이것은 성장에서 textblocks를 유지하는 일을하고있는 것 같다,하지만 한 가지 문제가있다목록 상자의 WPF Textblock이 제대로 자르지 않습니다
<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에서 잘라내어 붙여 넣기 만하면) 세로 스크롤 막대가 나타나므로 세로 스크롤 막대의 텍스트 블록 너비는 조정되지 않습니다.
TextBlock
을 ListBox
안에 세로 스크롤 막대가 있거나 없도록 유지하려면 어떻게해야합니까?
아주 좋은 질문입니다. 나는 이것이 WPF TextBlock의 버그라고 생각하는 경향이있다. – bitbonk