Reputation: 2128
So I got this RSS feed which I want to add to a certain part of the application window, so I'm using a ListBox:
<ListBox Name="listbox1" Width="600" Height="550" Margin="50"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
BorderBrush="Black" BorderThickness="2" Background="#443266" />
To bind the data from C#, I do this:
List<ListBoxItem> rssFeedList;
foreach (var item in myFeed)
{
foreach (Item i in item.Items)
{
ListBoxItem tb = new ListBoxItem();
tb.FontSize = 20.0;
tb.Content = i.Title + "\n";
tb.Foreground = Brushes.White;
tb.Margin = new Thickness(0, 10, 0, 0);
rssFeedList.Add(tb);
}
}
...
listbox1.ItemsSource = rssFeedList;
Just now, the application is fine, except that longer titles are not wrapped so appear off the Listbox, which I can't figure out.
Not sure whether this is the best UIElement to use neither? All I need is each RSS title to be displayed within a box.
Upvotes: 1
Views: 6040
Reputation: 5377
tb.Content = new TextBlock { Text = i.Title + "\n", TextWrapping = TextWrapping. };
choose your desired TextWrapping
Upvotes: 2