如何覆盖CustomButton类中的TouchUpInside事件?

时间:2015-02-24 04:09:22

标签: c# ios xamarin

我有一个自定义按钮:

public class CustomButton : UIButton
{
    public void HandleTouchUpInside(object sender, EventArgs ea)
    {
        Console.Write("test tap"); 
    }
}

所以我想在这个类中覆盖TouchUpInside事件......怎么做?

1 个答案:

答案 0 :(得分:2)

它会对你有用吗?

public class CustomButton : UIButton
{
    public CustomButton()
    {
        TouchUpInside += HandleTouchUpInside;

        // or new EventHandler(HandleTouchUpInside)
        // if Xamarin compiler/runtime doesn't allow such shorter code
    }

    public void HandleTouchUpInside(object sender, EventArgs e)
    {
        Console.Write("test tap"); 
    }
}