Reputation: 931
I have a listbox whose items contain only text. The listbox is having some fixed width. When I add a text which is having more width compare to the lisbox width, I am NOT able to see the remaining text.
Any solution will be helpful.
Upvotes: 0
Views: 4456
Reputation: 17631
If you're using WPF, add a text block and use it's text wrapping capabilities.
ListBox lb = new ListBox();
ListBoxItem li = new ListBoxItem();
TextBlock txtBlock = new TextBlock();
txtBlock.Width = 50;
txtBlock.TextWrapping = TextWrapping.Wrap;
...
li.Content = txtBlock;
lb.Items.Add(li);
If not, have a look at this answer for your question.
Upvotes: 0
Reputation: 25619
How about you remove the Width
property?
that way the control will expand automatically - as wide as the maximum item
EDIT: Might not be a good idea, BUT:
You could nest the ListBox inside a Panel, and set the Panel's width to a constant value, while having Scrollbars enabled. that way - even if there's a line WIDER than the other lines - the user will be able to scroll.
Upvotes: 1