在ListBox中的WP7 TextBlock没有包装文本

时间:2011-01-02 04:10:55

标签: windows-phone-7 listbox textblock

我有一个ListBoxStackPanel水平地持有TextBlockImage,然后是ContentPresenter。这就是XAML的样子:

<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>

我在页面构造函数中将ItemsSource的{​​{1}}设置为ListBox。一切正常,直到ObservableCollection文本变得太长,在这种情况下它不会像我指定的那样包装。如何强制Header包装文本?

感谢您的帮助!

1 个答案:

答案 0 :(得分:8)

这可能是因为没有限制TextBlock的宽度,所以它在屏幕上逐渐增长,你无法看到它。