Hello, I feel dumb, but migrating my app from gtk2 (libglade) to gtk3 (gtkbuilder) I done this example.
Compile with:
mcs win2labels.cs -pkg:gtk-sharp-3.0
It works but I want to do it without having to this for each object:
label1 = (Gtk.Label) builder.GetObject(“label1”);
In the past (with libglade, gtk2) it worked everything right with the autoconnect, but now I do not succeed. Any help?
Also I can’t find any c-sharp gtk3 software to inspect the code.
Thanks
---- win2labels.cs ----
using System;
using Gtk;
public class main
{
static Win2labels win2labels;
public static void Main (string[] args)
{
Gtk.Application.Init (); //needed
win2labels = Win2labels.Show ();
Gtk.Application.Run ();
}
}
public class Win2labels
{
static Win2labels Win2labelsBox;
Gtk.Window window;
Gtk.Label label1;
Gtk.Label label2;
public Win2labels ()
{
Builder builder = new Builder();
builder.AddFromFile ("win2labels.glade");
window = (Gtk.Window) builder.GetObject("window");
//can this program work without next two lines?
label1 = (Gtk.Label) builder.GetObject("label1");
label2 = (Gtk.Label) builder.GetObject("label2");
//builder.Autoconnect (window);
builder.Autoconnect (this);
label1.Text = "Hello!";
label2.Text = "Bye!";
}
static public Win2labels Show ()
{
Win2labelsBox = new Win2labels ();
Win2labelsBox.window.Show ();
return Win2labelsBox;
}
}
---- win2labels.glade ----
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkWindow" id="window">
<property name="can-focus">False</property>
<property name="title" translatable="yes">title of window</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">this is label1</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">this is label2</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>