移动对象ViewportControl WP8 [英] Move object in ViewportControl WP8

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

问题描述

我使用的是ViewportControl左右滚动,放大和缩小我的地图。在这张地图上我有一个绿色椭圆形,我希望走动。以前我用了一个ScrollViewer中,我设定的ScrollViewer的manipulationMode进行控制,从而使得它能够走动我的椭圆。不过,我找不到的ViewportControl类似的方式。那么,有没有四处移动我的椭圆形的方式

I'm using the ViewportControl to scroll around and zoom in and out of my Map. In this map I've got a green ellipse which I wish to move around. Previously I used a ScrollViewer where I set the manipulationMode of the ScrollViewer to control, and thus making it capable of moving my ellipse around. However I can't find a similar way for the ViewportControl. So is there a way to move my ellipse around?

到目前为止,我已经得到的代码是:

The code I've got so far is:

XAML中的一部分,我已经在我的地图我ViewportControl

The xaml part where I have my ViewportControl around my map

   <ViewportControl x:Name="ViewPortTestTest" Bounds="0,0,1271,1381.5" Height="480" Width="800" Canvas.ZIndex="1" Grid.Row="1">
        <ViewportControl.RenderTransform>
            <CompositeTransform x:Name="myTransformTest"/>
        </ViewportControl.RenderTransform>

        <View:Map x:Name="ZoomableContent" >
            <View:Map.RenderTransform>
                <CompositeTransform x:Name="myTransform" />
                <!-- ScaleX="{Binding Map.imageScale}" ScaleY="{Binding Map.imageScale}"/>-->
            </View:Map.RenderTransform>
        </View:Map>
    </ViewportControl>



这是在我加入椭圆地图。在ViewModel在那里我处理我的椭圆

It is in the map where I add the ellipse. The viewModel where I manipulate my ellipse

public void ManStart(ManipulationStartedEventArgs e)
    {

        e.Handled = true;

        ViewportControl VP = FindParentOfType<ViewportControl>(ChampViewModelSel);


       }
    }

    public void ManDelta(ManipulationDeltaEventArgs e)
    {
        e.Handled = true;


        Point fingerPosition = e.DeltaManipulation.Translation;

        Temp.x = fingerPosition.X;
        Temp.y = fingerPosition.Y;

        }
    }



在哪里Temp.x和温度。 ,y是椭圆的新位置

Where Temp.x and Temp.y is the new position of the ellipse.

推荐答案

我认为你可以尝试使用的从XNA的TouchPanel Touch.FrameReported 事件用于此目的。也许地图和VieportControl处理操纵事件,所以它不会与您的代码触发。

I think you could try to use TouchPanel from XNA and Touch.FrameReported event for this purpose. Probably Map and VieportControl handle the manipulation event so it won't fire with your code.

在我的提议 Touch_FrameReported 将每次触摸屏幕时开枪,所以我们只检查情况我们所需要的 - 这里来 IsGestureAvailable TouchAction 。简单的代码可以是这样的:

In my proposal Touch_FrameReported will be fired every time you touch the screen, so we have to check only for situations we need - here comes IsGestureAvailable and TouchAction. Simple code can look like this:

public MainPage()
{
    InitializeComponent();
    TouchPanel.EnabledGestures = GestureType.FreeDrag;
    Touch.FrameReported += Touch_FrameReported;
}

private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
    if (TouchPanel.IsGestureAvailable) // check only dragging 
    {
       // get point relative to Viewport
       TouchPoint mainTouch = e.GetPrimaryTouchPoint(ViewPortTestTest);
       // check if drag has completed (key up)
       if (mainTouch.Action == TouchAction.Up)
       {
          Temp.x = mainTouch.Position.X;
          Temp.y = mainTouch.Position.Y;
       }
    }
}

您可以阅读更多关于手势在这里MSDN 并的 nofollow的>。

You can read more about Gestures here at MSDN and on this blog.

您还可以检查其他GestureTypes和例如检查 TouchAction.Down 和用户在你的椭圆点击。

You can also check other GestureTypes and for example check if TouchAction.Down and user clicked on your Ellipse.

这些方法给你很多可能性读接触点操作,所以也许它会帮助。

These methods give you many possibilities to read TouchPoints and their Actions so maybe it will help.

我花了一段时间才能找到一种方法如何禁用Vieport。我发现了一个小'黑客'为,它会更容易,如果你的VieportControl只有水平或垂直(有锁属性,但为不工作)。下面是这个小'黑客',这应该禁用水平和垂直滚动:

It took me a while to find a way how to disable Vieport. I've found a little 'hack' for that, it will be easier if your VieportControl was only horizontal or vertical (there is a lock property, but doesn't work for both). Here is this little 'hack' which should disable both horizontal and vertical scrolling:

Rect originalBounds = new Rect();
private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
    TouchPoint myTouchPoint = e.GetPrimaryTouchPoint(ViewPortTestTest);
   // disable scrolling
   if (myTouchPoint.Action == TouchAction.Down) // here probably some other statement like if user hit ellipse
   {
       originalBounds = ViewPortTestTest.Bounds;
       ViewPortTestTest.Bounds = ViewPortTestTest.Viewport; // set current view as Bounds
   }

    // more logic

   // enable once again
   if (myTouchPoint.Action == TouchAction.Up)
        ViewPortTestTest.Bounds = originalBounds;
}

当我想禁用滚动 - 我设置了VieportControl的边界到目前观点(我记得原有的)。当我想启用滚动 - 我带回原来的边界

When I want to disable scrolling - I set bounds of the VieportControl to the current view (and I remember original ones). When I want to enable scrolling - I bring back original bounds.

在我测试过它 - 这是工作 - 当然,它需要锁定,如果多一点逻辑语句,所以它不会每次锁定你触摸屏幕。

As I've tested it - it is working - of course it needs a little more logic in locking if statement, so that it won't lock every time you touch the screen.

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

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