我的列表框
有(其中包括)中有一个描述字段可能相当长。而不是有水平滚动条我想自动换行了。
它的工作原理,如果我设置了了maxWidth
但由于列表框
更改大小我不想硬code值
什么是做到这一点的最好方法是什么?
编辑:该说明是在的TextBlock
简体XAML(去掉unnessesary的东西,仍然显示问题:
<列表框了borderThickness =0填充=5NAME =lstTasks>
< ListBox.ItemsSource>
<绑定源={的StaticResource dataTasks}/>
< /ListBox.ItemsSource>
< ListBox.ItemTemplate>
<的DataTemplate>
<电网>
< TextBlock的文本={绑定路径= RequestDescription}的TextTrimming =WordEllipsisTextWrapping =自动换行高度=60/>
< /网格>
< / DataTemplate中>
< /ListBox.ItemTemplate>
< /列表框>
解决方案
试着强迫你的ListBoxItems的宽度为列表框的宽度:
<列表框
NAME =lstTasks
了borderThickness =0
填充=5
HorizontalContentAlignment =拉伸>
你也可以尝试禁用水平滚动:
<列表框
ScrollViewer.HorizontalScrollBarVisibility =已禁用
...>
My ListBox
has, amongst other things a description field in it which can be quite long. Instead of having a horizontal scroll bar I want to word wrap it.
It works if I set the MaxWidth
but since the ListBox
changes size I don't want to hard code the value.
What's the best way to do this?
EDIT: The description is in a TextBlock
.
Simplified XAML (Removed unnessesary stuff, still shows problem:
<ListBox BorderThickness="0" Padding="5" Name="lstTasks">
<ListBox.ItemsSource>
<Binding Source="{StaticResource dataTasks}"/>
</ListBox.ItemsSource>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Path=RequestDescription}" TextTrimming="WordEllipsis" TextWrapping="Wrap" Height="60" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
解决方案
Try forcing the width of your ListBoxItems to be the width of the ListBox:
<ListBox
Name="lstTasks"
BorderThickness="0"
Padding="5"
HorizontalContentAlignment="Stretch">
Also you might try disabling horizontal scrolling:
<ListBox
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
...>