doot
doot

Reputation: 23

listBox Text Will Not Wrap

I'm trying to write a simple app that would parse a feedburner feed (in XML), extract data from the feed, scrub out some unnecessary data and then spit it out onto the screen.

I'm having difficulties wrapping the text in the listBox. I've spent the past few nights banging my head against the desk in an effort to get this to work. I've installed the Silverlight Toolkit and am trying to use WrapPanel, but it doesn't seem to want to work. The text displays fine in the listBox, I just can't seem to get the text to wrap.

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

Here's the snippet of code that I'm using to add the items to the 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);

                    }
                }
            }

Any help would be greatly appreciated!

UPDATE

I was able to get the text to populate the TextBlock by using this line:

textBlock1.Inlines.Add(areaName);

instead of this line:

listBox1.Items.Add(areaItem);

The only issue I seem to be running into now is the TextBlock not populating below the TextBlock area and not being scrollable.

UPDATE 2

Fixed this by removing the Height="x" line in the XAML. I am all set to go!

Upvotes: 2

Views: 1564

Answers (1)

i_am_jorf
i_am_jorf

Reputation: 54600

Put the text in a TextBlock and turn on wrapping?

Inside your listbox:

<TextBlock Text="{Binding}" TextWrapping="Wrap"/>

Upvotes: 2

Related Questions