我正在尝试使用 mono Gtk# 编写一个简单的表单应用程序,但我已经卡在了开始我创建一个继承自 Gtk.Dialog 的 Dialog 表单。用于收集基本信息并将这些信息作为对象返回到主窗口或触发某些事件到主窗口的对话框表单,因此它可以执行在这种情况下应该执行的操作,将数据绑定到 TreeView 控件(这是另一回事)。这些是我迄今为止尝试过的;
对话代码
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);
}
}
调用拨号的 MainWindow 代码
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 控制下的作用,我将不胜感激。