niewolny.info … yet another .net blog.

29Nov/140

ListBox using WrapPanel with VerticalScrollBar

Recently I was using a ListBox in Silverlight together with the WrapPanel. Idea wasn't too complicated, just a list and a button to add items. Each time the button was pressed, some items was generated in code behind and added to the list. If there was no space left for the new item, the wrap panel was expected to do his job, wrap the line and vertical scroll-bar was expected to be showed. So far so good... but it was not working as expected.
So the code was looking more less like this one:

 

Nothing special, a button, a list box, wrap panel for items template and vertical scroll-bar. Should work - but unfortunately result was far from expected:

listbox_wrappanel_unexpected

Hmm... ok .. so what we do now? Well, there are two solutions for this problem:

  1. We can disable horizontal scrolling what would force wrapping panel to do its job.
  2. Or we can modify a Template of the ListBox and add a ScrollViewer there:

Now - everything works is as expected:

listbox_wrappanel_expected

I know, I know - it's nothing complicated - it's more like a memo for myself - I hope next time when I will forget it, it will save me some time 😉

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.