none
Why do mouse events get promoted beside Touch events?

    Question

  • I would like to know please, how to prevent WPF promoting mouse events when the source of the event is a touch ?

    I read the article of JoshB here but, the mouse events keep getting triggered, although I did e.Handled = true;

    Here is what JoshB says:

    The touch event flow with no manipulations. The touch events are unhandled, so WPF promotes the event to the mouse equivalent

    So, I tried in my code to mark the event as handled, but WPF still promotes mouse events once I touch the_touchCanvas which is InkSurface

    Here is my code: ( I am not using Microsoft Surface SDK )

    _touchCanvas.IsManipulationEnabled=true;
    _touchCanvas.TouchDown+=newEventHandler<TouchEventArgs>(touchDown);
    _touchCanvas.TouchMove+=newEventHandler<TouchEventArgs>(touchMove);
    _touchCanvas.TouchEnter+=newEventHandler<TouchEventArgs>(touchEnter);
    _touchCanvas.TouchLeave+=newEventHandler<TouchEventArgs>(touchLeave);

    _touchCanvas.ManipulationDelta+=newEventHandler<ManipulationDeltaEventArgs>(ManipulationDelta);
    _touchCanvas.ManipulationStarting+=newEventHandler<ManipulationStartingEventArgs>(ManipulationStarting);
    _touchCanvas.ManipulationCompleted+=newEventHandler<ManipulationCompletedEventArgs>(ManipulationCompleted);


    void touchDown(object sender,TouchEventArgs e)
    {
    e.Handled=true;
    }
    void touchMove(object sender,TouchEventArgs e)
    {
    e.Handled=true;
    }
    void touchLeave(object sender,TouchEventArgs e)
    {
    e.Handled=true;
    }


    voidManipulationDelta(object sender,ManipulationDeltaEventArgs e)
    {
        e.Handled=true;
    }

    voidManipulationStarting(object sender,ManipulationStartingEventArgs e)
    {
        e.Handled=true;
    }
    voidManipulationCompleted(object sender,ManipulationCompletedEventArgs e)
    {
       e.Handled=true;
    }


    hopewise

    Monday, April 16, 2012 7:07 AM

All replies

  • Hi hopewise:

    This is a quick note to let you know that I am working on your issue.

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 17, 2012 9:25 AM
    Moderator
  • Thanks Sheldon .. I appreciate that 

    hopewise

    Wednesday, April 18, 2012 11:54 AM
  • Hi hopewise,

        I tried a very simple sample code(just using TextBox) to reproduce your problem, but I get the right event triggered as describeld here http://msdn.microsoft.com/en-us/library/ms754010.aspx#touch_and_manipulation,

    <Grid Background="Blue" MouseDown="Grid_MouseDown" MouseLeftButtonDown="Grid_MouseLeftButtonDown">      
                <TextBox x:Name="txtBox" Width="200" Height="50" HorizontalAlignment="Center" VerticalAlignment="Center" Background="DarkCyan"
                         IsManipulationEnabled="True"
                         ManipulationDelta="txtBox_ManipulationDelta"
                         ManipulationInertiaStarting="txtBox_ManipulationInertiaStarting"
                         ManipulationCompleted="txtBox_ManipulationCompleted"
                        
                         MouseLeftButtonDown="txtBox_MouseLeftButtonDown"
                         MouseDown="txtBox_MouseDown"                    
                         TouchDown="txtBox_TouchDown"
                         TouchMove="txtBox_TouchMove"
                         TouchEnter="txtBox_TouchEnter"
                         TouchLeave="txtBox_TouchLeave"/>
        </Grid>

     private void txtBox_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
            {
                MessageBox.Show("txtBox_ManipulationDelta is fired!");
                e.Handled = true;

            }

            private void txtBox_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e)
            {
                MessageBox.Show("txtBox_ManipulationInertiaStarting is fired!");
                e.Handled = true;

            }

            private void txtBox_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
            {
                MessageBox.Show("txtBox_ManipulationCompleted is fired!");
                e.Handled = true;

            }

            private void txtBox_TouchDown(object sender, TouchEventArgs e)
            {
                MessageBox.Show("txtBox_TouchDown is fired!");
                e.Handled = true;

            }

            private void txtBox_TouchMove(object sender, TouchEventArgs e)
            {
                MessageBox.Show("txtBox_TouchMove is fired!");
                e.Handled = true;
            }

            private void txtBox_TouchEnter(object sender, TouchEventArgs e)
            {
                MessageBox.Show("txtBox_TouchEnter is fired!");
                e.Handled = true;

            }

            private void txtBox_TouchLeave(object sender, TouchEventArgs e)
            {
                MessageBox.Show("txtBox_TouchLeave is fired!");
                e.Handled = true;

            }

            private void txtBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                MessageBox.Show("txtBox_MouseLeftButtonDown is fired!");
                e.Handled = true;

            }

            private void txtBox_MouseDown(object sender, MouseButtonEventArgs e)
            {
                MessageBox.Show("txtBox_MouseLeftButtonDown is fired!");
                e.Handled = true;

            }

            private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
            {
                MessageBox.Show("Grid_MouseDown is fired!");
                e.Handled = true;
            }

            private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                MessageBox.Show("Grid_MouseLeftButtonDown is fired!");
                e.Handled = true;
            }

    The results are as follows,

    1. when running with touch screen, just the  TouchDown="txtBox_TouchDown"
                           TouchMove="txtBox_TouchMove"
                           TouchEnter="txtBox_TouchEnter"
                           TouchLeave="txtBox_TouchLeave" events works;
    2. when running without touch screen, the touch events doesn't get triggerd, the mouse events get triggered.

    So here  I would like to know that if you could provide your project to reproduce your problem.

    Best Regards,

    Jenny Li [MSFT]

    Tuesday, May 01, 2012 8:16 AM