问题
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.
My ScrollViewer is:
<ScrollViewer Width="768" Height="380" HorizontalScrollBarVisibility="Hidden">
<View:Map/>
</ScrollViewer>
The unit where I apply the manipulation is:
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);
}
回答1:
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;
}
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
回答2:
Does the Unit have a property of Zindex? If yes, set Zindex of Scrollviewer and try setting the Unit ZIndex to a higher value than Scrollviewer.
回答3:
How about something like creating a global Map variable lets say named MyMap.
When you navigate to a page that contains your map and do (App.Curren as App).MyMap = //your map on the page.
When you do MouseDown and it is being triggered in "when I select the unit" you block all moving allowances of the map in
(App.Current as App).MyMap.IsScrollable = false; //or something like that.
So that map couldn't scroll when your "UNIT" is in MouseDown state and only "UNIT" was movable. And on MouseUp in "UNIT" undo the:
(App.Current as App).MyMap.IsScrollable = true;
来源:https://stackoverflow.com/questions/20213406/moving-object-in-scrollviewer