[Gtk-sharp-list] widget inheritance
Peter Williams
peter at newton.cx
Thu Jul 28 10:12:34 EDT 2005
The object that's being returned by gxml.GetWidget is created by Glade
based on the definitions in myfile.glade. That file probably defines
entry1 to just be a Gtk.Entry, not a MyEntry. This would be what you'd
expect if you just created the XML file through the glade UI because it
doesn't even know what a MyEntry is. So the entry1 object in your Glade
tree is a Gtk.Entry, which can't be cast into its subclass MyEntry.
I think it's possible to edit the XML file manually and put in a
"custom" widget, telling the Glade code to create an object of a type
you specify (eg, MyEntry). Alternatively, you can create the MyEntry
yourself, extract its parent from the Glade.XML object, and then add it
as a child manually.
HTH,
Peter
On Thu, 2005-07-28 at 23:48 +1000, Bryan Buchanan wrote:
> Hi,
>
> Can someone please tell a dummy why the last line of code below
> barfs with an error:
>
> "Cannot cast from source type to destination type."
>
> I obviously don't understand something fundamental !
>
> Bryan
>
> public class MyEntry : Gtk.Entry {
> public bool flag;
>
> public MyEntry() : base () {}
> public MyEntry(System.IntPtr ptr) : base(ptr) {}
> public MyEntry(string s) : base(s) {}
> protected MyEntry(GLib.GType type) : base(type) {}
> }
>
> Glade.XML gxml = new Glade.XML ("myfile.glade", "window1", null);
> Gtk.Entry test = (Gtk.Entry) gxml.GetWidget("entry1"); // OK
> MyEntry entry = (MyEntry) gxml.GetWidget("entry1"); // barfs
>
>
> _______________________________________________
> Gtk-sharp-list maillist - Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>
--
Peter Williams / peter at newton.cx
More information about the Gtk-sharp-list
mailing list