2012-08-09 38 views
3

我正在實現一個事件結構來將信息從View傳遞給Presenter。在視圖中,單擊一個按鈕時,下面的代碼被稱爲:調用委託時發生NotImplementedException

private void alterCmpd1() 
{ 
    EventHandler AlterEvent = AlterCompound1_Action; 
    if (AlterEvent != null) AlterEvent(this, EventArgs.Empty); 
} 

public event EventHandler AlterCompound1_Action; 

出於某種原因,一個NotImplementedException總是出現在:

AlertEvent(this, EventArgs.Empty); 

有人能幫助我弄清楚爲什麼?從發言類

代碼:

public MainPresenter(IMainView view, IModel model) 
    { 
     this.view = view; 
     this.view.AlterCompound1_Action += new EventHandler(view_AlterCompound1); 
     this.model = model; 
     view.Show(); 
    } 

    void view_AlterCompound1(object sender, EventArgs e) 
    { 
     // I commented out this code, on the off 
     // chance that it was affecting things. Still no luck. 
    } 

回答

1

感謝威爾,我意識到我犯的錯誤。我一直在使用「構建解決方案」工具,但我忽略了查看Visual Studio 2010的構建配置管理器(構建 - >配置管理器)。在那裏,我發現這一點:

Screenshot of configuration manager in VS2010

之前,其中的一些構建列複選標記(對應於我編輯的項目,如QAz.Presenter和QAz.View)的沒有選擇,那麼「 Build Solution「正在跳過它們。選擇這些項目後,Visual Studio知道在我運行解決方案時構建它們。

5

90%肯定,如果你看一下,你會發現這一點。

private void AlterCompound1_Action(object, EventArgs e) 
{ 
    throw new NotImplementedException(); 
} 
+0

不幸的是,沒有。那會讓我的生活更輕鬆。 – 2012-08-09 20:23:58

+0

@QtotheC:我敢打賭,如果你刪除了MainPresenter類,重新編譯並運行異常會以任何方式發生。嘗試一下。 – Will 2012-08-09 20:39:02

+0

是的,你是對的。我認爲它會抱怨在別的地方錯過了一堂課。是什麼造成的?這與我的代碼文件在不同類中被拆分有什麼關係?我在VS 2010工作,並告訴它重建解決方案。 – 2012-08-09 20:43:22