listBox文本不会包装

时间:2011-02-03 00:27:20

标签: silverlight xaml windows-phone-7

我正在尝试编写一个简单的应用程序来解析feedburner Feed(以XML格式),从Feed中提取数据,清除一些不必要的数据,然后将其吐出到屏幕上。

我在listBox中包装文本时遇到了困难。我花了几个晚上把头撞在桌子上,试图让它发挥作用。我已经安装了Silverlight Toolkit并尝试使用WrapPanel,但它似乎不想工作。文本在listBox中显示正常,我似乎无法将文本包装好。

 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

            <ListBox  x:Name="listBox1" Width="456" Height="646" ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <toolkit:WrapPanel />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
            </ListBox>
    <Grid>

以下是我用于将项目添加到listBox的代码片段:

StringReader stream = new StringReader(e.Result);
            XmlReader reader = XmlReader.Create(stream);
            string areaName = String.Empty;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "description")
                    {
                        areaName = reader.ReadElementContentAsString();
                        areaItem = new ListBoxItem();
                        areaItem.Content = areaName;
                        listBox1.Items.Add(areaItem);

                    }
                }
            }

非常感谢任何帮助!

更新

我能够通过使用以下行来获取文本填充TextBlock:

textBlock1.Inlines.Add(areaName);

而不是这一行:

listBox1.Items.Add(areaItem);

我现在遇到的唯一问题是TextBlock没有填充在TextBlock区域下面而且不可滚动。

更新2

通过删除XAML中的Height =“x”行来解决此问题。我准备好了!

1 个答案:

答案 0 :(得分:2)

将文本放入TextBlock并打开包装?

在列表框中:

<TextBlock Text="{Binding}" TextWrapping="Wrap"/>
相关问题