How do I connect glade signals using GtkBuilder in C#?

懵懂的女人 提交于 2019-12-10 22:57:49

问题


In python, I could just do builder.connect_signals(self). It doesn't seem like this method exists in C#, and after looking at the GtkBuilder documentation, it looks like python is the exception, rather than the rule. How would I accomplish the same thing in C#?


回答1:


Right now Gtk.Builder is not fully implemented in the current version of Gtk# (2.12). This thread explains the current situation. So once Gtk# 2.14 is released, you can just do:

builder.Autoconnect (this);

In the meantime you could use Glade.XML, and then convert your code (and glade files) as described here: http://lists.ximian.com/pipermail/gtk-sharp-list/2008-October/009157.html




回答2:


You can connect your signals using method Autoconnect, but method that represent a signal in c# must be in form:

static void customMethod(object sender, EventArgs args);

So each field of class that you use in such method must be declared as static. It robs you of creating another instance of your class.

There is another way of connecting signals:

Builder builder = new Builder();
builder.AddFromFile("custom.glade");
Button button = (Button)builder.GetObject("closeButton");
button.Clicked += delegate {
    Application.Quit();
}


来源:https://stackoverflow.com/questions/1693454/how-do-i-connect-glade-signals-using-gtkbuilder-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!