Why do mouse events get promoted beside Touch events?
-
2012年4月16日 7:07
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
_touchCanvaswhich isInkSurfaceHere 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
全部回复
-
2012年4月17日 9:25版主
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.
-
2012年4月18日 11:54Thanks Sheldon .. I appreciate that
hopewise
-
2012年5月1日 8:16
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,
- when running with touch screen, just the TouchDown="txtBox_TouchDown"
TouchMove="txtBox_TouchMove"
TouchEnter="txtBox_TouchEnter"
TouchLeave="txtBox_TouchLeave" events works; - 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]
- when running with touch screen, just the TouchDown="txtBox_TouchDown"

