silverlight下的平移效果

发布于 2024-11-07 16:25:29 字数 174 浏览 0 评论 0原文

祝大家有美好的一天, 我很难找到有关如何在 silverlight 中创建这种酷平底锅效果的信息。有人可以帮我吗? 这是一个 Flash 站点的链接,具有我需要的效果。 http://www.marcecko.com/#/

Good day to all,
I am having difficulty finding information on how to create this cool pan effect in silverlight. Can any one help me out?
This is a link to a flash site that has the effect that i need.
http://www.marcecko.com/#/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心碎无痕… 2024-11-14 16:25:29

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

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 中的工作原理应该几乎相同。 --编辑-- 在两种技术中都进行了测试。

+1 很酷的问题! :)

I really liked the effect too, so I recreated it using Behaviors:

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);

    }
}

Just add this behavior to ANY ScrollViewer, and it simply works. as an example, this 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>

Note that I've tested this only in WPF, but it should work pretty much the same in Silverlight. --EDIT-- Tested it, in both technologies.

+1 for cool question! :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文