views:

96

answers:

2

Hello,

I want to retrieve a child of the window I am in Gtk#. So far the only way I found looking at the documentation is to do it using a loop through the Children property of the Window, like:

foreach (Widget w in this) 
{
    if (w.Name == "MyWidget")
        return w;
}

where this is the window.

I am sure there must be a better, cleaner and efficient way to directly retrieve a particular child widget from an element, based on some of its properties.

Thanks for your help!

+1  A: 

Sergi,

Maybe it is better for you to create a field for particular widget in your window class derived from Gtk.Window? This is the best practice for me.

Best regards, Oleg Yaroshevych

Oleg Yaroshevych
I understand what you mean, and I already do that. But to assign the widget to the field I have to know first which widget is the one I want.It can be easily solved with the Observer pattern as well. I guess I was looking for a nice shortcut to these more verbose solutions, but thanks!!
Sergi
A: 

You can retrieve any child (it doesn't matter if it is a child of a child ... of a child of a window) with its variable name like this:

return this.MyWidget
blazt