I've ran into a bug in MAUI and I just wanted to know if I'm the only one or if I'm doing something wrong in this new environment :)
Before I've always been able to do this when navigating to a new page via a button click:
private async void OnButtonClicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new Page1());
}
But it does not seem to work anymore, this is how my Page1 looks like in C# code:
public partial class Page1 : ContentPage
{
public Page1()
{
InitializeComponent();
}
protected override async void OnAppearing()
{
base.OnAppearing();
await MainThread.InvokeOnMainThreadAsync(async () => { await LoadRecipes(); });
}
private async Task LoadRecipes()
{
//no code yet
}
}
}
When I run this code and click the button, nothing happens.
You can navigate using this in a ButtonClick or TapGestureRecongnizer.
private void TapGestureRecognizer_Tapped_2(object sender, EventArgs e)
{
App.Current.MainPage = new NavigationPage(new Page1());
}
Or in a Button.
private void Button_Clicked(object sender, EventArgs e)
{
App.Current.MainPage = new NavigationPage(new Page1());
}
Try this: First in your App.xaml.cs
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
}
Then in your MainPage you can do what you are attempiting to do:
private async void btnNav_Clicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new Page1());
}
This is supposed to work and to keep track of user's navigation, but in some weird scenarios im facing this is not working very well, but it's the solution that Microsoft documents on it's getting started guide. I would like to see more information in their Maui guide about navigation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With