在silverlight泛影响

时间:2011-05-17 19:17:04

标签: silverlight animation

大家好日子, 我很难找到有关如何在silverlight中创建这种酷炫效果的信息。谁能帮我吗? 这是一个闪存网站的链接,具有我需要的效果。 http://www.marcecko.com/#/

1 个答案:

答案 0 :(得分:2)

我也非常喜欢这个效果,所以我使用行为重新创建了它:

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很酷的问题! :)