Why OnMouseDown handler exists but is not called f

2019-09-02 01:30发布

问题:

I have an ellipse (inside a grid of a UserControl) and created this event handler for MouseDown but why it is never called ?

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

I have no children inside the ellipse so there is no event bubbling involved. This is crazy behavior.

回答1:

By default the 'Fill' on an ellipse, and other shapes is null. If you set it to any color at all (even transparent), you fill find that clicking on it will give you the behavior that you desire. Alternatively, if you click the existing ellipse (with null fill) just on the edge, you will get your event.