Search code examples
c#silverlightwindows-phone-7

Click on grid in windows phone


I Have grid in my XAML and couple of buttons on it. And i want to get notified every time the user press the grid so i add MouseEnter Event:

<Grid x:Name="LayoutRoot" Background="#FF1F1F1F" MouseEnter="TapMouse">

But my problem is that every time one of the buttons is pressed so this method called too.

Any way to disable it? or any other way to implement it?

Thanks


Solution

  • First set break points in each event block.

    Find out which one is firing first the button or the grid

    Declare a bool at the top and call it buttonClicked = false;

    if it is the button then put a buttonClicked = true in the but event

    if its the grid then I would try and see if you could use a buttonOver event

    In the grid event wrap it all in an if statement if(!buttonClicked)

    That should work

    NOTE you will have to also add a buttonClicked = false into maybe focus lost event for the button

    Update: Coming back to this answer years later I acknowledge it's ghettoness. Though i'd like to update it, I think leaving it as a time capsule of my own ignorance is much more beneficial.