Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a Click event to an Ellipse in code behind?

Tags:

c#

click

wpf

To add a click event to a Button in C# code behind, I can do this

Button btn = new Button;
btn.Click += btn_Click;

What if I have an Ellipse, which does not contain a Click?

Ellipse e = new Ellipse;
e.??? += e_Click;
like image 485
KMC Avatar asked Apr 06 '11 02:04

KMC


2 Answers

One way to do that is make button an ellipse and attatch .Click Event handler.

<Button>
    <Button.Template>
        <ControlTemplate>
            <Ellipse .../>
        </ControlTemplate>
    </Button.Template>
</Button>
like image 172
Sanjeevakumar Hiremath Avatar answered Nov 10 '22 13:11

Sanjeevakumar Hiremath


Maybe the MouseUp event will serve your purpose. Try

Ellipse ellipse = new Ellipse();
ellipse.MouseUp += ellipse_MouseUp;

private void ellipse_MouseUp(object sender, MouseButtonEventArgs e)
{
   ...
}
like image 24
Bala R Avatar answered Nov 10 '22 15:11

Bala R