接口:
public delegate int ChildEventHandle(object arg1, object arg2);
public interface IChildEvent
{
event ChildEventHandle add;
}
ChildPage继承接口:
class ChildPage: Window,IChildEvent
{
#pragma warning disable
public MainWindow parentWindow;
public event ChildEventHandle add;
public event ChildEventHandle sub;
public event ChildEventHandle mulity;
#pragma warning restore
protected virtual void AddEvent(object arg1, object arg2)
{
//实例化委托对象,发起调用
ChildEventHandle handle = add;
if (arg1.GetType().ToString() == "System.Int32" && arg2.GetType().ToString() == "System.Int32")
handle(arg1, arg2);
else MessageBox.Show("参数输入有误,请重新输入!!");
}
}
WindowChild继承ChildPage
public partial class WindowChild : ChildPage
{
public WindowChild()
{
InitializeComponent();
base.parentWindow = this;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
//调用父类中已经默认实现的类发起事件
base.AddEvent(txtBox1.Text, txtBox2.Text);
}
}
报错如下,我应该怎么添加事件处理函数呢:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
WindowChild son = new WindowChild();
//定义真正的事件处理函数,通过lamba表达式
//son.add+=????????报错,找不到add
}
}