-1

I seems like the MouseUp event of my inner Grid isn't firing, because of the MouseDown Event from the surrounding Grid. Any way I can prevent this?

<Grid HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="525" MouseDown="Grid_MouseDown_1" Background="#00000000">
        <Grid HorizontalAlignment="Left" Height="20" Margin="495,10,0,0" VerticalAlignment="Top" Width="20" Background="#FF000000" MouseEnter="gridBtn_MouseEnter" MouseLeave="gridBtn_MouseLeave" MouseUp="gridBtn"/>             
</Grid>
TheMadGuy
  • 97
  • 6
  • Have you tried debugging? Could be an issue in your `MouseEnter` or `MouseLeave` event that is keeping `MouseUp` event from firing. – trix Mar 06 '18 at 13:35

2 Answers2

0

You never receive MouseDown for the second grid, hence no MouseUp for the second grid. In order for the MouseDown event to propagate to the child you probably need to handle PreviewMouseDown to have a first crack at the event. You would then perform some kind of hit-testing.

Anyway, the reason your handler is not called is probably due to e.Handled = true.

E.g.:

private void Grid_MouseDown_1(object sender, MouseButtonEventArgs e)
{
    // Uncomment to allow the MouseUp event for the second grid.
    e.Handled = true;
}
l33t
  • 18,692
  • 16
  • 103
  • 180
0

i tested the following and it works without problems.

    private void gridBtn(object sender, MouseButtonEventArgs e)
    {
        Debug.WriteLine("MouseUp inner grid");
    }

    private void Grid_MouseDown_1(object sender, MouseButtonEventArgs e)
    {
        Debug.WriteLine("MouseDown outer grid");
    }

    private void gridBtn_MouseEnter(object sender, MouseEventArgs e)
    {
        Debug.WriteLine("MouseEnter inner grid");
    }

    private void gridBtn_MouseLeave(object sender, MouseEventArgs e)
    {
        Debug.WriteLine("MouseLeave inner grid");
    }

MouseDown and Mouseup

i just changed the colors for the grids to make it easy for me to see. i hope it helps..

na th
  • 135
  • 6