-
How does inheritance work? Specifically calling the parent's constructor. I want to subclass Goal is something like this class MyWindow : Adw.ApplicationWindow
{
public MyWindow(Gtk.Application app) : base(app)
{
// Do stuff
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Well some progress, I did this class MyWindow : Adw.ApplicationWindow
{
public MyWindow(Gtk.Application app) : base(app.Handle, false)
{
// Do stuff
}
} That fixed the constructor idea, but now when I
|
Beta Was this translation helpful? Give feedback.
-
okay after looking closer at how Adw.Application.New works I realized this is the correct way: class MyWindow : Adw.ApplicationWindow
{
public MyWindow(Gtk.Application app) : base(New(app).Handle, false)
{
// Do stuff
}
} This works, though I'm unsure if that's the best practice, how are others dealing with it? |
Beta Was this translation helpful? Give feedback.
-
Seems like the alternative is to not initialize the constructor but then later when presenting the window use According to Gtk docs this is equivalent to setting the application property of the window so that works and looks better. |
Beta Was this translation helpful? Give feedback.
-
To create a proper subclass which is known to the GObject typesystem you would need to call into this constructor In your case this would be this constructor. In general I would advice against subclasses as GTK itself is trying to avoid it. In general for a C# programmer I would only recommend subclasses if there are specific arguments for it (similar to GTK) as inheritance chains are not very flexible and tend to lead to complex / harder to maintain code. |
Beta Was this translation helpful? Give feedback.
Seems like the alternative is to not initialize the constructor but then later when presenting the window use
application.AddWindow
According to Gtk docs this is equivalent to setting the application property of the window so that works and looks better.