Мне очень понравился эффект, поэтому я воссоздал его, используя Поведения:
public class PanBehavior : Behavior<ScrollViewer>
{
protected override void OnAttached()
{
this.AssociatedObject.MouseMove += new MouseEventHandler(AssociatedObject_MouseMove);
this.AssociatedObject.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
this.AssociatedObject.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
}
void AssociatedObject_MouseMove(object sender, MouseEventArgs e)
{
var mousePos = e.GetPosition(this.AssociatedObject);
double panningY = this.AssociatedObject.ExtentHeight - this.AssociatedObject.ViewportHeight;
double panningX = this.AssociatedObject.ExtentWidth - this.AssociatedObject.ViewportWidth;
double relativeMouseY = mousePos.Y / this.AssociatedObject.ActualHeight;
double relativeMouseX = mousePos.X / this.AssociatedObject.ActualWidth;
panningY *= relativeMouseY;
panningX *= relativeMouseX;
this.AssociatedObject.ScrollToVerticalOffset(panningY);
this.AssociatedObject.ScrollToHorizontalOffset(panningX);
}
}
Просто добавьте это поведение в ЛЮБОЙ ScrollViewer, и он просто работает.Например, это xaml:
<Grid>
<ScrollViewer>
<i:Interaction.Behaviors>
<local:PanBehavior />
</i:Interaction.Behaviors>
<UniformGrid Width="1000" Height="1000" Rows="10" Columns="10">
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
<Button Content="Hello" />
</UniformGrid>
</ScrollViewer>
</Grid>
Обратите внимание, что я проверял это только в WPF, но в Silverlight он должен работать примерно так же.--EDIT-- Протестировал, в обеих технологиях.
+ 1 за крутой вопрос!:)