开发者

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

开发者 https://www.devze.com 2023-02-22 03:14 出处:网络
To add a click event to a Button in C# co开发者_StackOverflow社区de behind, I can do this Button btn = new Button;

To add a click event to a Button in C# co开发者_StackOverflow社区de 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;


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

<Button>
    <Button.Template>
        <ControlTemplate>
            <Ellipse .../>
        </ControlTemplate>
    </Button.Template>
</Button>


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)
{
   ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号