Animation 操纵DeltaEventArgs未为图像元素触发-WP8

Animation 操纵DeltaEventArgs未为图像元素触发-WP8,animation,windows-phone-8,Animation,Windows Phone 8,我在xaml中定义了一个列表框,如下所示。每个项目都由一个画布组成,其中包含一个图像元素。我已经为图像声明了ManipulationEvents <ListBox x:Name="CategoryLB" SelectionChanged="CategoryClicked" Margin="0,131,0,0"> <ListBox.ItemTemplate> <DataTemplate> <Canvas Wi

我在xaml中定义了一个列表框,如下所示。每个项目都由一个画布组成,其中包含一个图像元素。我已经为图像声明了
ManipulationEvents

<ListBox x:Name="CategoryLB" SelectionChanged="CategoryClicked" Margin="0,131,0,0">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Canvas Width='460'  Height="130" Background="#FF0D6B97" Margin="10,10,10,10" >
                   <Image Width='480'  Height="150" Source="{Binding Page}" Stretch="None" Opacity="1" CacheMode="BitmapCache"
                         ManipulationDelta="ImageManipulationDelta"
                         ManipulationCompleted="ImageManipulationCompleted"
                         ManipulationStarted="ImageManipulationStarted"/>        
            </Canvas>
                    </DataTemplate>
        </ListBox.ItemTemplate>
</ListBox>

这里有什么我遗漏的吗?

我对图像进行了处理,处理过程如下。。 我希望这能对你有所帮助

<Image x:Name="imgViewer" CacheMode="BitmapCache" Source="/MetroImages/mapmetro.png" Stretch="Uniform">
                            <Image.RenderTransform>
                                <ScaleTransform x:Name="scaleTrans" ScaleX="2" ScaleY="2" CenterX="150" CenterY="200"  />
                            </Image.RenderTransform>
                            <toolkit:GestureService.GestureListener>
                                <toolkit:GestureListener 
            PinchStarted="GestureListener_PinchStart" 
            PinchDelta="GestureListener_PinchDelta" 
            PinchCompleted="GestureListener_PinchComplete"
                    DragStarted="GestureListener_DragStart"
            DragDelta="GestureListener_DragDelta"
            DragCompleted="GestureListener_DragCompleted"/>                                  
                            </toolkit:GestureService.GestureListener>
                        </Image>

然后在事件处理程序中

private readonly DispatcherTimer m_animationTimer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(10) };
        private double _cx, _cy;

        private void GestureListener_PinchStart(object sender, PinchStartedGestureEventArgs e)
        {
            Point p1 = e.GetPosition(imgViewer, 0);
            Point p2 = e.GetPosition(imgViewer, 1);

            scaleTrans.CenterX = (p1.X + ((p2.X - p1.X) / 2));
            scaleTrans.CenterY = (p1.Y + ((p2.Y - p1.Y) / 2));

            _cx = scaleTrans.ScaleX;
            _cy = scaleTrans.ScaleY;
        }

        private void GestureListener_PinchDelta(object sender, PinchGestureEventArgs e)
        {
            // Compute new scaling factors
            double cx = _cx * e.DistanceRatio;
            double cy = _cy * e.DistanceRatio;

            // If they're between 1.0 and 4.0, inclusive, apply them
            if (cx >= 1.0 && cx <= 4.0 && cy >= 1.0 && cy <= 4.0)
            {
                if ((cy - 1) < 0.1 && (cx - 1) < 0.1)
                    cx = cy = 1;

                scaleTrans.ScaleX = cx;
                scaleTrans.ScaleY = cy;
            }
        }

        private void GestureListener_PinchComplete(object sender, PinchGestureEventArgs e)
        {
        }

        private void GestureListener_DragStart(object sender, DragStartedGestureEventArgs e)
        {
        }

        private void GestureListener_DragDelta(object sender, DragDeltaGestureEventArgs e)
        {
            scaleTrans.CenterX = (scaleTrans.CenterX - e.HorizontalChange);
            scaleTrans.CenterY = (scaleTrans.CenterY - e.VerticalChange);

            if (scaleTrans.CenterX < 0)
            {
                scaleTrans.CenterX = 0;
            }
            else if (scaleTrans.CenterX > imgViewer.ActualWidth)
                scaleTrans.CenterX = imgViewer.ActualWidth;

            if (scaleTrans.CenterY < 0)
            {
                scaleTrans.CenterY = 0;
            }
            else if (scaleTrans.CenterY > imgViewer.ActualHeight)
                scaleTrans.CenterY = imgViewer.ActualHeight;
        }

        private void GestureListener_DragCompleted(object sender, DragCompletedGestureEventArgs e)
        {
        }
private readonly dispatchermer m_animationTimer=new dispatchermer(){Interval=TimeSpan.frommilluses(10)};
私人双卡;
私有void GestureListener_PinchStart(对象发送方,PinchStartedTestureEventArgs e)
{
点p1=e.GetPosition(imgViewer,0);
点p2=e.GetPosition(imgViewer,1);
scaleTrans.CenterX=(p1.X+((p2.X-p1.X)/2));
scaleTrans.CenterY=(p1.Y+((p2.Y-p1.Y)/2));
_cx=scaleTrans.ScaleX;
_cy=scaleTrans.ScaleY;
}
private void GestureListener_PinchDelta(对象发送方,PinchGetureEventArgs e)
{
//计算新的比例因子
双cx=_cx*e.距离比;
double cy=_cy*e.距离比;
//如果它们介于1.0和4.0之间(含1.0和4.0),请应用它们
如果(cx>=1.0&&cx=1.0&&cy imgViewer.ActualWidth)
scaleTrans.CenterX=imgViewer.ActualWidth;
if(scaleTrans.CenterY<0)
{
scaleTrans.CenterY=0;
}
else if(scaleTrans.CenterY>imgViewer.ActualHeight)
scaleTrans.CenterY=imgViewer.ActualHeight;
}
私有void GestureListener_DragCompleted(对象发送方,DragCompletedGestureEventArgs e)
{
}

您的代码没有问题,但问题是delta事件不会在emulator上触发,我已经在emulator和设备上测试了您的代码,并且在设备上运行良好,所以不要担心,在设备上测试您的代码….

我无法使用toolkit,因为GestureService在WP8hey@alfah中不推荐使用,我尝试了您的代码和我一起工作很好。。。操作增量每次都被调用。啊,我正在模拟器上测试。它在那里不起作用。你能在模拟器上试试吗?是的,我在模拟器上测试过,delta没有被触发,但这不应该是问题,因为它在设备上工作得很好…非常感谢!这一整天我都在为这个挠头。如果你能把它贴出来作为答案,我会把它标记为答案。
private readonly DispatcherTimer m_animationTimer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(10) };
        private double _cx, _cy;

        private void GestureListener_PinchStart(object sender, PinchStartedGestureEventArgs e)
        {
            Point p1 = e.GetPosition(imgViewer, 0);
            Point p2 = e.GetPosition(imgViewer, 1);

            scaleTrans.CenterX = (p1.X + ((p2.X - p1.X) / 2));
            scaleTrans.CenterY = (p1.Y + ((p2.Y - p1.Y) / 2));

            _cx = scaleTrans.ScaleX;
            _cy = scaleTrans.ScaleY;
        }

        private void GestureListener_PinchDelta(object sender, PinchGestureEventArgs e)
        {
            // Compute new scaling factors
            double cx = _cx * e.DistanceRatio;
            double cy = _cy * e.DistanceRatio;

            // If they're between 1.0 and 4.0, inclusive, apply them
            if (cx >= 1.0 && cx <= 4.0 && cy >= 1.0 && cy <= 4.0)
            {
                if ((cy - 1) < 0.1 && (cx - 1) < 0.1)
                    cx = cy = 1;

                scaleTrans.ScaleX = cx;
                scaleTrans.ScaleY = cy;
            }
        }

        private void GestureListener_PinchComplete(object sender, PinchGestureEventArgs e)
        {
        }

        private void GestureListener_DragStart(object sender, DragStartedGestureEventArgs e)
        {
        }

        private void GestureListener_DragDelta(object sender, DragDeltaGestureEventArgs e)
        {
            scaleTrans.CenterX = (scaleTrans.CenterX - e.HorizontalChange);
            scaleTrans.CenterY = (scaleTrans.CenterY - e.VerticalChange);

            if (scaleTrans.CenterX < 0)
            {
                scaleTrans.CenterX = 0;
            }
            else if (scaleTrans.CenterX > imgViewer.ActualWidth)
                scaleTrans.CenterX = imgViewer.ActualWidth;

            if (scaleTrans.CenterY < 0)
            {
                scaleTrans.CenterY = 0;
            }
            else if (scaleTrans.CenterY > imgViewer.ActualHeight)
                scaleTrans.CenterY = imgViewer.ActualHeight;
        }

        private void GestureListener_DragCompleted(object sender, DragCompletedGestureEventArgs e)
        {
        }