0
我想要在一個簡單的C#WinForms應用程序中實現MVP模式。視圖左側是一個樹形視圖,其中包含應用程序保存的文件列表;在視圖的右側是一個DataGridView,用於顯示在樹視圖中單擊的任何文件,或用於輸入以保存爲新文件。這些文件只是使用BinaryFormatter寫入磁盤的Dictionary對象。MVP - 從視圖獲取數據到演示者
我創建的視圖的接口:
public interface IMappingsView
{
event EventHandler SaveMapping;
event EventHandler NewMapping;
event EventHandler<DeleteArgs> DeleteMapping;
event EventHandler PasteData;
event EventHandler NodeClicked;
}
視圖上的刪除按鈕具有以下Click事件處理程序:
private void buttonDeleteMapping_Click(object sender, EventArgs e)
{
var node = treeView1.SelectedNode.Text;
var args = new DeleteArgs(Path.Combine(RootDir,node));
if (DeleteMapping != null)
{
DeleteMapping(this, args);
dataGridView1.Rows.Clear();
RefreshTreeView();
}
}
什麼是從傳遞信息的最佳方式觀看主持人?我覺得每個場景都需要自定義事件參數是非常錯誤的。
謝謝@戴夫布什,工作得很好。您如何從Presenter中的DataGridView獲取數據? – Tony
基本方法相同。使您想要綁定到窗體和界面中的屬性的數據源。該模式總是相同的,無論數據類型如何,您需要訪問的任何方法或屬性都在接口中定義並在表單中實現。 –