[英]Optimal way to retrieve a child widget in Gtk#
I want to retrieve a child of the window I am in Gtk#. 我想检索我在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: 到目前为止,我发现查看文档的唯一方法是使用循环遍历Window的Children
属性的方法,例如:
foreach (Widget w in this)
{
if (w.Name == "MyWidget")
return w;
}
where this
is the window. this
是窗户
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! 谢谢你的帮助!
Sergi, Sergi,
Maybe it is better for you to create a field for particular widget in your window class derived from Gtk.Window? 也许最好在从Gtk.Window派生的窗口类中为特定小部件创建一个字段? This is the best practice for me. 这对我来说是最佳做法。
Best regards, Oleg Yaroshevych 此致Oleg Yaroshevych
您可以使用以下变量名检索任何子项(无论它是窗口的子项还是子项都没有关系):
return this.MyWidget
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.