gpt4 book ai didi

c# - 在 ScrollViewer 中移动对象

转载 作者:太空宇宙 更新时间:2023-11-03 10:53:56 25 4
gpt4 key购买 nike

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

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

}

最佳答案

我最终自己找到了问题的解决方案。因为我将 ManipulationMode 设置为控制,所以我想我禁用了一些属性,这些属性最终会在您移动对象时产生延迟。所以我最终尝试在移动对象时制作一个 Storyboard,这解决了问题并在我选择要移动的对象时提供了一个很好的平滑运动。我所做的是进入我的 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/ 从后面的代码中添加了一些 Storyboard作为指导方针。每次我选择对象并激活 ManipulationDelta 时都会出现 ManDelta

关于c# - 在 ScrollViewer 中移动对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20213406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com