我有我的自定義EventArgs
在一個單獨的類文件,我可以從不同類別後來引用它的工作:定義事件處理程序用的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;
在的DataSource這是在MasterViewController我可以提高第E事件:
if (this.controller.RowClicked != null) {
this.controller.RowClicked (this, new RowSelectedEventArgs (this.controller.list [indexPath.Row]));
}
正如你可以看到我在數據源有一個字段(控制器)與我引用的事件。現在我有一個搜索源與相同的概念(也稱爲控制器)。現在SearchSource我想提出一個事件:
if (this.controller.RowClicked != null) {
this.controller.RowClicked (this, new RowSelectedEventArgs (this.list [indexPath.Row]));
}
,但我得到
事件「SplitView.MasterViewController.RowClicked」只能出現在 左邊的+ =或 - =類型之外使用時 'SplitView.MasterViewController'
唯一的區別是,SearchSource不是類的一部分MasterViewController(因爲它與數據源)。但事件是public
所以它應該工作?
如何從不同的課程中培養同一個活動?
它是相同的類型。 – testing 2014-09-11 11:34:42