0
我想用單聲道Gtk#編寫一個簡單的窗體應用程序,但我已經卡在開始我創建一個Dialog窗體繼承自Gtk.Dialog。對話框形式用於收集基本信息並將這些信息作爲對象返回到主窗口或觸發某個事件到主窗口,以便在此情況下可以執行它所做的事情,將數據綁定到TreeView控件(這是另一個故事)。這些是我迄今爲止所嘗試的;Mono Gtk.Dialog返回對象作爲響應
對話框代碼
public partial class MyDialog : Gtk.Dialog
{
public MyDialog()
{
this.Build();
}
protected void OnButtonOkClicked (object sender, EventArgs e)
{
int portNumber = 0;
iint.TryParse (spnPort.Text, out portNumber);
var myObj = new MyObj();
myObj.Username = txtUsername.Text;
myObj.Password = txtPassport.Text;
// did not work as ParentWindow is a Gdk.Window
//(this.ParentWindow as MainWindow).AddObj(myObj);
//Also did not work because there is no response related method
//or property in the Dialog please read below code block this will make more sense
//this.OnResponse(myObj);
}
}
主窗口的代碼來調用對話框幷
protected void OnAddActionActivated (object sender, EventArgs e)
{
MyDialog s = new MyDialog();
s.Run();
s.Response += HandleResponse;
}
void HandleResponse (object o, ResponseArgs args)
{
//as this event has args.Args and args.RetVal I thought one would do what I wanted
//maybe I am using them all wrong
}
我很感激,如果有人能解釋什麼是Gdk.Window是什麼,它正在Gtk控制下進行。