我EventArgs
在一个单独的类文件中有我的自定义,以后可以从不同的类中引用它:
using System;
using System.Collections.Generic;
namespace SplitView
{
public class RowSelectedEventArgs:EventArgs {
public Patient selectedRow { get; set; }
public RowSelectedEventArgs(Patient selectedRow) : base(){
this.selectedRow = selectedRow;
}
}
}
在我的MasterViewController我定义了我的事件
public event EventHandler<RowSelectedEventArgs> RowClicked;
在MasterViewController中的DataSource中,我可以引发事件:
if (this.controller.RowClicked != null) {
this.controller.RowClicked (this, new RowSelectedEventArgs (this.controller.list [indexPath.Row]));
}
如您所见,我的DataSource中有一个字段(控制器),我用它来引用事件。现在我有一个具有相同概念的SearchSource (也称为控制器的字段)。现在在SearchSource我想提出这个事件:
if (this.controller.RowClicked != null) {
this.controller.RowClicked (this, new RowSelectedEventArgs (this.list [indexPath.Row]));
}
但我明白了
事件 'SplitView.MasterViewController.RowClicked' 只能出现在 += 或 -= 的左侧,当在类型 'SplitView.MasterViewController' 之外使用时
唯一的区别是SearchSource不是MasterViewController类的一部分(与DataSource一样)。但是事件是public
这样的,它应该起作用吗?
如何从不同的班级引发相同的事件?