在 ScrollViewer 中移动对象 [英] Moving Object in ScrollViewer

查看:51
本文介绍了在 ScrollViewer 中移动对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序使用 MVVM 设置,并且我正在使用 scrollViewer 来滚动地图.在这张地图上,我有一个单位,当我选择它时我想四处移动.但是,当我选择该单元时,我的 ScrollViewer 仍处于激活状态,有没有办法绕过 scrollViewer 或停用它,以便我可以四处移动该单元.我已经尝试将 ManipulationModeProperty 更改为 Control,但是当我四处移动时,这会使单位滞后.

I'm using the MVVM setup, for my app and I'm using an scrollViewer to scroll around an map. On this map I have an unit which I'd like to move around when I select it. However when I select the unit my ScrollViewer is still activated, is there an way to work around the scrollViewer or deactivate it such that I can move the unit around. I already tried changing the ManipulationModeProperty to Control, but thius makes the unit lag when I move it around.

我的滚动查看器是:

 <ScrollViewer Width="768" Height="380" HorizontalScrollBarVisibility="Hidden">
        <View:Map/>
 </ScrollViewer>

我应用操作的单位是:

 public void ManStart(ManipulationStartedEventArgs e)
    {

        myScrollViewer.SetValue(ScrollViewer.ManipulationModeProperty, ManipulationMode.Control);

    public void ManDelta(ManipulationDeltaEventArgs e)
    {

        Point fingerPosition = e.DeltaManipulation.Translation;

        Unit.x = fingerPosition.X + ChampModelSel.x;
        Unit.y = fingerPosition.Y + ChampModelSel.y;

    }

public void ManCompleted(ManipulationCompletedEventArgs e)
    {

        var myScrollViewer = FindParentOfType<ScrollViewer>(ChampViewModel) as        ScrollViewer;
        myScrollViewer.SetValue(ScrollViewer.ManipulationModeProperty, ManipulationMode.System);

    }

推荐答案

我最终自己找到了解决问题的方法.因为我将 ManipulationMode 设置为 control,所以我想我禁用了一些属性,这些属性最终会在您移动对象时出现延迟.因此,当我移动对象时,我最终尝试制作故事板,这解决了问题,并在我选择要移动的对象时提供了很好的平滑运动.我所做的是进入了我的 ManDelta:

I ended up finding a solution for the problem myself. Because I set the ManipulationMode to control, I guess I disable some propertys which end up giving an lag when you move your object. So I ended up trying to make a storyboard when ever I move my object, which fixed the problem and gives me a nice smooth motion when I select the object I wish to move. What I did was I went into my ManDelta:

 public void ManDelta(ManipulationDeltaEventArgs e)
{

    Point fingerPosition = e.DeltaManipulation.Translation;

    Unit.x = fingerPosition.X + ChampModelSel.x;
    Unit.y = fingerPosition.Y + ChampModelSel.y;

}

并从后面的代码中添加了一些故事板,使用这个 http://www.buzzfrog.se/index.php/2013/06/create-storyboards-in-code-for-windows-phone/ 作为指南.每次我选择对象并激活 ManipulationDelta 时都会发生 ManDelta

and added some storyboard from the code behind, using this http://www.buzzfrog.se/index.php/2013/06/create-storyboards-in-code-for-windows-phone/ as a guide line. The ManDelta occurs every time I select the object and activate the ManipulationDelta

这篇关于在 ScrollViewer 中移动对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆