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

Chris Howie cdhowie at gmail.com
Thu Nov 26 05:55:50 EST 2009

On Thu, Nov 26, 2009 at 12:21 AM, Chuck Esterbrook
<chuck.esterbrook at gmail.com> wrote:
> Hi,
> I'd like to associate an arbitrary Mono/.NET object with a widget.
> Something like:
>    button.Data = "foo"
> or:
>    menuItem.Data = new MyClass();

There are two options here...

1. Create a Dictionary<Widget, T> (you pick the T according to your
needs) and use that dictionary to map widgets to the data you want to
associate with them.

2. Derive the widget classes and create a property on them for your needs.

The reason that the "user data" mechanism is marked obsolete is
because it's completely the wrong way to model something like this and
usually creates more problems than it solves.

Chris Howie

More information about the Gtk-sharp-list mailing list