[Gtk-sharp-list] Associate user data object with a widget

Adam Tauno Williams awilliam at whitemice.org
Mon Nov 30 14:05:32 EST 2009


> > There are several GUI framework authors who think user data is okay
> > given that GUI libs tend to have this feature including GTK+,
> > WinForms, WPF and Silverlight. See also:
> > http://stackoverflow.com/questions/1058635/common-uses-for-the-tag-property
> >
> > I've used this technique in other GUI libs without experiencing a
> > single problem. It's just an alternate way to stash data in an
> > existing object.
> The main problems with this approach are type safety and collisions.
> In the case of winforms, where each control has a Tag property, you

Agree, The UserData thing is kind of lousy.  But if you wrap it in
extension methods it can be used more gracefully.  Extension methods
can't add attributes [variables] but they can store and retrieve stuff
from UserData.

  public static class MyWidgetMethods
  {
    public static void MyMethod(this Gtk.Object widget, {some params})
    {
	{do stuff and use this.UserData here}
        return {whatever}
    }
  }



More information about the Gtk-sharp-list mailing list