Search code examples
animationwindows-phone-8

ManipulationDeltaEventArgs not firing for image element - WP8


I have a list box defined as below in my xaml. Every item consists of a canvas with an image element inside it. I have declared ManipulationEvents for the image.

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

The problem is ManipulationDelta is not fired at all. Only ManipulationStarted and ManipulationCompleted gets called and hence my animation does not get the translation values. Looks straightforward to me.

These are the ManipulationEvents

    private void ImageManipulationStarted(object sender, ManipulationStartedEventArgs e)
    {
        FrameworkElement transformElement = ((FrameworkElement)sender) as FrameworkElement;
        transformElement.SetHorizontalOffset(0);
    }

    private void ImageManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
    {
        FrameworkElement transformElement = ((FrameworkElement)sender) as FrameworkElement;

        if (Math.Abs(e.TotalManipulation.Translation.X) > transformElement.ActualWidth / 3)
        {
            if (e.TotalManipulation.Translation.X < 0.0)
            {
                ToDoItemDeletedAction(transformElement);
            }
            else
            {
                ToDoItemCompletedAction(transformElement);
            }
        }
        else
        {
            ToDoItemBounceBack(transformElement);
        }
    }

    private void ImageManipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {
        FrameworkElement transformElement = ((FrameworkElement)sender) as FrameworkElement;

        // handle the drag to offset the element
        double offset = transformElement.GetHorizontalOffset().Value + e.DeltaManipulation.Translation.X;
        transformElement.SetHorizontalOffset(offset);
    }    

Anything that Im missing here?


Solution

  • your code is all right but the problem is that the delta event will not fire on the emulator and i have tested your code both on emulator and device and its working fine on device so dont worry and test your code on device ....