Opening MainPage in Designer and adding a handler for the Loading event of the button solved the problem. The initialization of the button can be done in the handler.