Search code examples
c#wpfxamlgridmouseup

C# WPF - Grid MouseUp not firing due to previous Grid


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>

Solution

  • 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..