Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NullReferenceException when accessing GUI Components in Controllers constructor

In Mono I have a simple NSWindow with Controller on it I drop a NSSplitView and a NSButton.

If I try to access the NSSplitView out of the Contstructor or Initialize() Method I get a nullReferenceException. Instead if I try to access the NSSplitView from a ButtonClicked Method, it works.

Well, it seems that the Framework creates the GUI Components after the controller's Construtor is called. But where should I put my code to configure GUI Components if not in the Constructor?

Thanks in advance. Johannes

like image 265
john84 Avatar asked Mar 07 '26 16:03

john84


1 Answers

You should use the AwakeFromNib method in your controller class. It is called once all the objects have been loaded and properly connected.

public override void AwakeFromNib ()
{
    base.AwakeFromNib ();

    // Do something here with the outlets
}
like image 181
Laurent Etiemble Avatar answered Mar 10 '26 09:03

Laurent Etiemble