0

I have canvas with ellipse like this:

<Canvas 
     Name="c1" 
     Background="White" 
     MouseUp="c1_MouseUp">
        <Ellipse 
              Width="138" 
              Height="143" 
              Fill="Chocolate" 
              MouseUp="Ellipse_MouseUp">
        </Ellipse>
</Canvas>

With event handlers like this:

    private void Ellipse_MouseUp(object sender, MouseButtonEventArgs e)
    {
        MessageBox.Show("Ellipse click");
    }

    private void c1_MouseUp(object sender, MouseButtonEventArgs e)
    {
        MessageBox.Show("Canvas click");
    }

Both events fire when I click on ellipse. I want only Ellipse_MouseUp to fire.

Are there any simple methods to make it work as I want?

Kamil
  • 13,363
  • 24
  • 88
  • 183

1 Answers1

2

Mark the one you want to process e.Handled = True; http://msdn.microsoft.com/en-us/library/system.windows.input.mousebuttoneventargs.aspx

EDIT as an example the following should work:

void Ellipse_MouseUp(object sender, MouseButtonEventArgs e)
{
    e.Handled = True;
    MessageBox.Show("Ellipse click");
}
kenny
  • 21,522
  • 8
  • 49
  • 87
  • Related post with more details http://stackoverflow.com/questions/971459/wpf-button-single-click-double-click-problem – kenny Jul 13 '13 at 19:23
  • Thanks. I figured this out before you added code, but it will be useful for others :) – Kamil Jul 13 '13 at 19:24