[Gtk-sharp-list] Using g_object_set from Gtk#

Mike Kestner mkestner at novell.com
Thu Mar 16 13:37:38 EST 2006

On Thu, 2006-03-16 at 23:04 +1100, Jonathan Morgan wrote:
> In Gtk+, g_object_set(obj, prop, value) can be used to set arbitrary
> properties of an object, meaning that you can do things like replace
> gtk_show_window with g_object_set(window, "visible", TRUE).
> Is there any (accessible) binding to this facility in Gtk#?  If not,
> is there any way to do this in C# on any generic C# object (which
> would be more generally useful).

Closest thing is the protected GLib.Object.SetProperty method.  Gtk#
intentionally hides as much of GLib.Object as possible, exposing its
functionality in C# syntax (eg window.Visible = true;)

> I would like this functionality because I am working on a Gtk binding
> to Mercury, which I would like to have working with both Gtk# and
> Gtk+, and it would simplify the work if I can specify things once as
> calling object_set in Mercury, rather than once in C# and once in C.

Not sure I follow.  Maybe if you can clarify what you are trying to do I
could suggest alternative approaches?

> Also, is it possible to pass data to a Gtk# handler and have it passed
> back to your callback via. the EventArgs parameter (as you can do with
> the data parameter in Gtk+)?  This would be necessary for storing the
> Mercury procedure to call from the C# callback I register.

The Gtk# paradigm for the user_data parameter is to create your delegate
from an instance method on a class and hold the data member in an
instance field.

Mike Kestner <mkestner at novell.com>

More information about the Gtk-sharp-list mailing list