Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Creating a Horizontally Scrolling List in WP7

DZone's Guide to

Creating a Horizontally Scrolling List in WP7

· Mobile Zone
Free Resource

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

I recently needed to show someone how to make a ListBox scroll horizontally rather than vertically. Here's what I did:
<listbox itemssource="{Binding MyList}" scrollviewer.horizontalscrollbarvisibility="Auto" scrollviewer.verticalscrollbarvisibility="Disabled">
    <listbox.itemspanel>
        <itemspaneltemplate>
            <!-- Could be a VirtualizingStackPanel if you wish -->
            <stackpanel orientation="Horizontal">
        </stackpanel></itemspaneltemplate>
    </listbox.itemspanel>
    <listbox.itemtemplate>
        <datatemplate>
            <!-- Style set to enhance need for scrolling -->
            <textblock style="{StaticResource PhoneTextExtraLargeStyle}" text="{Binding}">
        </textblock></datatemplate>
    </listbox.itemtemplate>
</listbox>
The key part is: '<StackPanel Orientation="Horizontal" />'
It's this that controls the direction. of item display.

The next two parts give us the correct scrolling behaviour that we want.
Setting 'ScrollViewer.HorizontalScrollBarVisibility="Auto"' enables horizontal scrolling.
Setting 'ScrollViewer.VerticalScrollBarVisibility="Disabled"' prevents vertical scrolling.

The thing to note is that setting XxxxScrollBarVisibility doesn't just control the visibility if the scrollbar it also controls whether scrolling in that direction is possible.


Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.

Topics:

Published at DZone with permission of Matt Lacey, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}