列表框内的WP7 TextBlock不换行 [英] WP7 TextBlock inside a ListBox not wrapping text
问题描述
我有一个ListBox
,其中的StackPanel
s保持水平的TextBlock
和Image
,然后是ContentPresenter
.这就是XAML的样子:
I have a ListBox
which has StackPanel
s holding a TextBlock
and an Image
horizontally, followed by a ContentPresenter
. This is what the XAML looks like:
<Grid x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,0">
<ListBox x:Name="MainListBox"
Margin="12,0,12,0"
SelectionChanged="MainListBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu x:Name="ContextMenu"
Opened="ContextMenu_Opened">
<toolkit:MenuItem Header="edit"
Tag="edit"
Click="MenuItem_Click" />
<toolkit:MenuItem Header="delete"
Tag="delete"
Click="MenuItem_Click" />
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Left">
<!-- **** This text won't wrap **** -->
<TextBlock Text="{Binding Header}"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextNormalStyle}"
Foreground="{StaticResource PhoneAccentBrush}" />
<Image Source="/image.png"
Visibility="{Binding ImageVisibility}" />
</StackPanel>
<ContentPresenter Content="{Binding Content}"
HorizontalAlignment="Stretch" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment"
Value="Stretch" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</Grid>
我正在页面构造函数中将ListBox
的ItemsSource
设置为ObservableCollection
.一切正常,直到Header
文本变得太长为止,在这种情况下,它没有像我指定的那样自动换行.如何强制TextBlock
换行?
I'm setting the ItemsSource
of the ListBox
to an ObservableCollection
within the page constructor. Everything works fine until the Header
text becomes too long, in which case it is not wrapping as I've specified it to. How can I force the TextBlock
to wrap the text?
感谢您的帮助!
推荐答案
这很可能是由于未限制TextBlock的宽度,因此它在屏幕上水平增长,而您看不到它.
This is likely a result of not restricting the width of the TextBlock, so it is growing horizontaly off screen where you can't see it.
这篇关于列表框内的WP7 TextBlock不换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!