列表框内的WP7 TextBlock不换行 [英] WP7 TextBlock inside a ListBox not wrapping text

查看:102
本文介绍了列表框内的WP7 TextBlock不换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListBox,其中的StackPanel s保持水平的TextBlockImage,然后是ContentPresenter.这就是XAML的样子:

I have a ListBox which has StackPanels 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>

我正在页面构造函数中将ListBoxItemsSource设置为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆