Support for ScrollViewer Controls

Additional support has been added to provide simple scrolling behavior for several controls related to the ScrollViewer control. These include the ListBox, the ScrollViewer itself, and the ComboBox.

Adding Touch-Based Scrolling to the ListBox

Touch support can be added to ListBox controls via another behavior. This behavior allows "flick-based" scrolling in the ListBox as shown below:
<ListBox x:Name="SampleListBox" ItemTemplate="{StaticResource ItemTemplate}" ItemsSource="{Binding Collection}" Background="#FF222222">
	<i:Interaction.Behaviors>
		<Touch:ListBoxTouchScrollBehavior/>
	</i:Interaction.Behaviors>
	<ListBox.ItemsPanel>
		<ItemsPanelTemplate>
			<StackPanel/>
		</ItemsPanelTemplate>
	</ListBox.ItemsPanel>
</ListBox>

A Note About Virtualization in ListBox controls
ListBox controls in Silverlight support virtualization. When a ListBox is virtualized, the internal scrolling behavior is changed, and items can only be scrolled one full row at a time. This behavior interferes with a smooth scrolling experience. It may be desirable to prefer smooth scrolling over the performance enhancement afforded by virtualization, depending on how much certainty there is ahead of time that the ListBox will be presenting a limited set of items. To disable the virtualization, the ItemsPanel can be swapped out using an ItemsPanelTemplate, as indicated above.

Adding Touch-Based Scrolling to ScrollViewer Controls

Just like the ListBox control, the same scrolling can be added to instances of the the ScrollViewer control in much the same way. Instead of using the ListBoxTouchScrolBehavior, the ScrollViewerTouchScrollBehavior should be used.

Adding Touch-Based Scrolling to ComboBox Controls

Touch events include the notion of "promotion" to Mouse events - the default behavior of a Touch event is to raise a corresponding Mouse event on the conclusion of the Touch event. The default implementation of the ComboBox in Silverlight uses this Mouse event to close the ComboBox's Popup. This is "sub-optimal" for touch-based scrolling, since as soon as the scroll has happened, the ComboBox collapses the Popup. As a result, it is not enough to provide a behavior to override the ComboBox's behavior, and instead a new implementation of the ComboBox is included - the TouchableComboBox.

For situations where Touch-Based Scrolling is desired from a ComboBox, the regularComboBox control should be replaced with a TouchableComboBox in the markup.

Last edited Apr 3, 2011 at 3:11 AM by avidgator, version 3

Comments

No comments yet.