I found the answer, so I will answer myself.
1) How to make ListBox scroll smoothly:
This issue did not occur in SilverLight 2, and it only happens with SilverLight 3, in which VirtualizedStackPanel was introduced.
VirtualizedStackPanel provides much faster updates in case of huge lists (since only visible items are displayed)
There is a workaround for this (beware, it cannot be used in huge lists): you redefine the ListBox ItemPanelTemplate, so it uses a StackPanel:
<navigation:Page.Resources> <ItemsPanelTemplate x:Key="ItemsPanelTemplate"> <StackPanel/> </ItemsPanelTemplate> </navigation:Page.Resources> <StackPanel Orientation="Vertical" x:Name="LayoutRoot"> <ListBox x:Name="list" ItemsPanel="{StaticResource ItemsPanelTemplate}"> </ListBox> </StackPanel>
2) How to programmatically change the scroll position
See ListBox Subclass below: it provides an accessory for an internal ScrollViewer in a ListBox
3) How to catch MouseDown / Move / Up events in the list:
Subclass the ListBox as shown below. 3 methods:
internal void MyOnMouseLeftButtonDown(MouseButtonEventArgs e) protected override void OnMouseMove(MouseEventArgs e) protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
will be called, and you can do whatever you want with them. There is one subtle trick in that the OnMouseLeftButtonDown ListBox method is never called: you need to implement a ListBoxItem subclass where you can handle this event.
using System; using System.Collections.Generic; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace MyControls {
Pascal T.
source share