locked
Why an Image cann't response a PointerMoved message input by Touch?

    Question

  • <Page
        x:Class="SurfaceTest2.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:SurfaceTest2"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <ScrollViewer Background="Gray">
            <Grid>
                <Image Source="Assets/Logo.png" x:Name="Image_1" Width="600" Height="768"  HorizontalAlignment="Center" VerticalAlignment="Top" Margin="383,0" />
                <Button Click="Button_Click_1" Content="Button1" HorizontalAlignment="Left" Margin="90,556,0,0" VerticalAlignment="Top"/>
                <Button Click="Button_Click_2" Content="Button2" HorizontalAlignment="Left" Margin="90,630,0,0" VerticalAlignment="Top"/>
            </Grid>
        </ScrollViewer>
    </Page>

    This is my MainPage. And I add next in MainPage

    Image_1->PointerPressed += ref new PointerEventHandler(this, &MainPage::OnImagePointerPressed);
    
    Image_1->PointerReleased += ref new PointerEventHandler(this, &MainPage::OnImagePointerReleased);
    
    Image_1->PointerMoved += ref new PointerEventHandler(this, &MainPage::OnImagePointerMoved);

    So, the Image can response PointerMoved trigger by Pen moved.

    But It cann't trigger by Handle touch moved.

    Wednesday, October 17, 2012 6:52 AM

Answers

  • OK, Thanks Rob. After Two days wandering on MSDN.

    I solve this problem. Oh........., But I feel good now.

     

    disable the ScrollViewer's manipulations is not accurate,

    We need disable Image's ManipulationMode like this

    Image_1->ManipulationMode = ManipulationModes::None;

    Instead of scrollViewer->ManipulationMode = ManipulationModes::None;

     

    • Marked as answer by Jesse Jiang Thursday, October 18, 2012 6:24 AM
    Thursday, October 18, 2012 6:16 AM

All replies

  • Hi Jumping Fish,

    The problem is that you have two objects trying to handle the touch input here: your Image_1 control and the ScrollViewer it is hosted in. Once the ScrollViewer receives the PointerPressed event its manipulation engine starts up and essentially captures the pointer so that it can handle scrolling. Since it is doing so, the pointer events don't get routed to the Image control.

    Since the PointerPressed event will go to your Image control first you can avoid this by detecting that the you want to handle input on the Image instead of scrolling and disable the ScrollViewer's manipulations. Your PointerMoved and PointerReleased events will then fire for the Image_1 control as you'd like. Once the Image is done with the events you can reenable the ScrollViewer manipulations so that the user can scroll from outside the Image.

    --Rob

    • Proposed as answer by Can BilginMVP Wednesday, October 17, 2012 11:07 AM
    Wednesday, October 17, 2012 7:48 AM
    Owner
  • disable the ScrollViewer's manipulations

    reenable the ScrollViewer manipulations

    I had try so many kinds of ScrollViewer's properties, but it didn't work.

    MainPage::MainPage() { InitializeComponent(); // Set scroll event handler

    scrollViewer->ViewChanged += ref new EventHandler<ScrollViewerViewChangedEventArgs^>(this, &MainPage::OnScrollViewerChanged); scrollViewer->PointerPressed += ref new PointerEventHandler(this, &MainPage::OnScrollViewerPointerPressed); scrollViewer->PointerMoved += ref new PointerEventHandler(this, &MainPage::OnScrollViewerPointerMoved); bool bTest = scrollViewer->IsHorizontalScrollChainingEnabled; scrollViewer->IsHorizontalScrollChainingEnabled = false; scrollViewer->IsVerticalScrollChainingEnabled = false; scrollViewer->ManipulationMode = ManipulationModes::None; scrollViewer->IsHoldingEnabled = false; scrollViewer->IsHorizontalRailEnabled = false; scrollViewer->IsHorizontalScrollChainingEnabled = false; scrollViewer->IsScrollInertiaEnabled = false; scrollViewer->AllowDrop = false; scrollViewer->HorizontalScrollMode = ScrollMode::Disabled; scrollViewer->VerticalScrollMode = ScrollMode::Disabled; // .... }


    Didn't I missing some properties???
    • Edited by Jumping fish Thursday, October 18, 2012 6:00 AM Wrong Edit
    Thursday, October 18, 2012 1:47 AM
  • // Set scroll event handler
    scrollViewer->ViewChanged += ref new EventHandler<ScrollViewerViewChangedEventArgs^>(this, &MainPage::OnScrollViewerChanged);
    scrollViewer->Tapped += ref new TappedEventHandler(this, &MainPage::OnScrollViewerTapped);
    scrollViewer->PointerPressed += ref new PointerEventHandler(this, &MainPage::OnScrollViewerPointerPressed);
    scrollViewer->PointerMoved += ref new PointerEventHandler(this, &MainPage::OnScrollViewerPointerMoved);
    	
    scrollViewer->ManipulationStarted += ref new ManipulationStartedEventHandler(this, &MainPage::OnScrollViewerManipulationStarted);
    scrollViewer->ManipulationStarting += ref new ManipulationStartingEventHandler(this, &MainPage::OnScrollViewerManipulationStarting);
    scrollViewer->ManipulationDelta += ref new ManipulationDeltaEventHandler(this, &MainPage::OnScrollViewerManipulationDelta);
    scrollViewer->ManipulationCompleted += ref new ManipulationCompletedEventHandler(this, &MainPage::OnScrollViewerManipulationCompleted);
    
    I had set these eventHandler. But it didn't work.
    Thursday, October 18, 2012 5:59 AM
  • OK, Thanks Rob. After Two days wandering on MSDN.

    I solve this problem. Oh........., But I feel good now.

     

    disable the ScrollViewer's manipulations is not accurate,

    We need disable Image's ManipulationMode like this

    Image_1->ManipulationMode = ManipulationModes::None;

    Instead of scrollViewer->ManipulationMode = ManipulationModes::None;

     

    • Marked as answer by Jesse Jiang Thursday, October 18, 2012 6:24 AM
    Thursday, October 18, 2012 6:16 AM