Reputation: 107
Update: I edited the program, now the problem is that it is not recognizing the children section and the class in the button class
public App()
{
MainPage = new NavigationPage(new buttonPage());
NavigationPage.PushAsync(new buttonPage.hello());
}
and the buttonPage on the same file
public class buttonPage : ContentPage
{
public void hello()
{
Button hi = new Button
{
Text = "GO",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
Content = new ContentPage()
{
children = { hi }
};
}
}
Upvotes: 0
Views: 85
Reputation: 11040
You need a NavigationPage to wrap your main page so that you can transition to other pages.
If you want your MenuPage
to have a Back button then you'd use PushAsync, if you want it to replace the current page - PushModalAsync
Also: split your pages in separate classes and files, it quickly becomes way too messy to maintain page-within-page stuff
public class App: Application{
public App(){
MainPage = new NavigationPage(new ButtonPage());
}
...
}
public class ButtonPage : ContentPage{
...
async void OnButtonClicked(object sender, EventArgs args){
await Navigation.PushModalAsync(new MenuPage());
}
}
Upvotes: 2