在ScrollViewer中移动对象

时间:2013-11-26 09:44:32

标签: c# wpf windows-phone-8 scrollviewer

我正在使用MVVM设置,我的应用程序和我正在使用scrollViewer滚动地图。在这张地图上,我有一个单位,当我选择它时,我想移动它。但是,当我选择单元时,我的ScrollViewer仍处于激活状态,是否有办法解决scrollViewer或取消激活它以便我可以移动单元。我已经尝试将ManipulationModeProperty更改为Control,但当我移动它时,thius会使单位滞后。

我的ScrollViewer是:

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

    }

3 个答案:

答案 0 :(得分:2)

我最终找到了解决问题的方法。因为我将ManipulationMode设置为控制,我想我禁用了一些在移动对象时最终会产生延迟的属性。因此,当我移动我的物体时,我最终试图制作一个故事板,这解决了问题并在我选择我想移动的物体时给了我一个很好的平滑动作。我做的是我进入了我的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

答案 1 :(得分:0)

该单位是否拥有Z指数的财产?如果是,请设置Scrollviewer的Z Index并尝试将Unit ZIndex设置为高于Scrollviewer的值。

答案 2 :(得分:0)

如创建全局Map变量之类的东西可以说是名为MyMap。

导航到包含地图的页面时(App.Curren as App).MyMap = //您的地图在页面上。

当您执行MouseDown并且在“当我选择单位时”触发它时,您将阻止地图的所有移动限额

(App.Current as App).MyMap.IsScrollable = false; //or something like that.

因此,当“UNIT”处于MouseDown状态且只有“UNIT”可移动时,地图无法滚动。在“UNIT”中的MouseUp上撤消:

(App.Current as App).MyMap.IsScrollable = true;