views:

15

answers:

1

I have a list of 100 or so items. I'd like to output all the items to the page, one beneath the other. Maybe 25 or so items will be visible initially, and when the users scrolls, the rest of the list will be visible.

The catch here is that I don't want to use the ListBox's scrollbar - I want to use the page's scrollbar. (By page, I mean the aspx page which contains the Silverlight object.) I can easily remove the scrollbar on the ListBox, but then only the top 25 items are visible. And even if I make the ListBox's height arbitrarily large, the ListBox will only be as big as the viewable area of the page - so that even if I scroll the page itself there's nothing more to see!

To clarify what I'm trying to do - imagine a simple HTML page with a list of items:

<ul>
   <li>Item One</li>
   <li>Item Two</li>
   ...
   </li>Item One Hundered</li>
</ul>

You only see some of the items initially, but when you scroll the page, the rest become visible.

I'm trying to do something similar in Silverlight. Is ListBox the wrong control to use?

+1  A: 

If you are just displaying items and don't need interactivity, you want to use a ItemsControl. If you need the interactivity of a ListBox then I believe you want to structure it like so (not tested)

<ScrollViewer>
    <StackPanel>
        <ListBox VerticalAlignment="Stretch" />
    </StackPanel>
<ScrollViewer>

That should give you ListBox infinite area and therefore it will stretch to max size.

Stephan
This doesn't create a ListBox that is longer than the viewable portion of the page. I suspect that what I'm trying to do isn't possible in Silverlight.
MCS
I pretty sure it is possible. You need to make sure that there is no control above your `ListBox` that has a fixed height. If no control has a fixed height (this includes the App itself) then it should expand to fill the necessary. You also need to check that your html allows for the Silverlight app to expand as necessary.
Stephan