无法将类型'MouseEventHandler'隐式转换为'RoutedEventHandler

时间:2011-04-30 13:40:23

标签: wpf silverlight

我尝试继承方法button1_click,我收到了上面的消息,如何修复?

namespace visualinheritance
{
    public partial class usercontrolcommon : UserControl
    {
        public usercontrolcommon()
        {
            InitializeComponent();
        }

        public void button1_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("usercontrolcommon");
        }
    }
}

namespace visualinheritance
{
    public partial class usercontrol1 : usercontrolcommon
    {
        public usercontrol1()
        {
            InitializeComponent();
            this.button1.Click += new MouseEventHandler(button1_Click);

        }

    }
}

1 个答案:

答案 0 :(得分:2)

按钮单击事件不是鼠标事件。只需将处理程序更改为button1.Click += button1_Click;即可使用