Reputation: 19937
I have a PhoneApplicationPage
with some grids, images and a few buttons. If I tap outside my buttons, anywhere in the page (on an image, grid or whatever), I want to open a new page.
How can I detect a tap/click anywhere on the page?
Upvotes: 0
Views: 1055
Reputation: 39007
I see at least two ways to do that:
MouseLeftButtonUp
event on your PhoneApplicationPage
. It should be triggered by images and labels but not by buttonsListen to the Tap
event on your PhoneApplicationPage
. However, this event will be triggered even when the user tap on a button. To prevent this, you can retrieve the list of controls at the tap coordinates in the event handler, and open the new page only if there's no button:
private void PhoneApplicationPage_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
var element = (UIElement)sender;
var controls = VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(element), element);
if(controls.OfType<Button>().Any())
{
return;
}
// Open the new page
}
Upvotes: 1