What is the purpose of InitializeComponent() method in Page?

Technology CommunityCategory: XamarinWhat is the purpose of InitializeComponent() method in Page?
VietMX Staff asked 3 years ago

This method is auto-generated when we add any new XAML Page to the project. It instantiates and initializes all the objects which we have defined into the XAML file. It connects them with each other based on their parent child relations. It attaches the Event Handlers we defined in the code with the Events, we set in the XAML. Then, it generates the whole tree of objects like a content of a page.

We should never access any control of our page before this call because before this call, none of the controls get initialized or exist and so, we will get an Exception.