Пан эффект в серебряном свете - PullRequest
3 голосов
/ 17 мая 2011

Добрый день всем, мне трудно найти информацию о том, как создать этот крутой эффект панорамирования в серебряном свете.Может кто-нибудь мне помочь?Это ссылка на флеш сайт, который мне нужен.http://www.marcecko.com/#/

1 Ответ

2 голосов
/ 18 мая 2011

Мне очень понравился эффект, поэтому я воссоздал его, используя Поведения:

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 за крутой вопрос!:)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...