Reputation: 21
I inherited a Xamarin project that has to be migrated to .Net MAUI. My current issue is that the hamburger icon is not visible. I can drag the menu from the left hand side, and works fine. It's built with a flyout page and a navigation service that to be honest, this last one I don't trully understand. If I comment the initialization of the service, the hamburger icon appeares but the menu items throw an exception once clicked. I already took a look at github but it's seems to be a current issue: https://github.com/dotnet/maui/issues/22116 https://github.com/dotnet/maui/issues/18228
The main goal is to have a hamburger menu item that displays the flyoutpage to enable the user navigate all the pages. But due to the project built arround this navigation service, the routing, viewmodels initialization, and so on. I fear that if I bypass it I would have to do a lot of recode.
Does anyone faced the same problem and have a workarround?
public partial class App : Application
{
public App()
{
InitializeComponent();
Resources["DefaultStringResources"] = new Resx.AppResources();
DependencyService.Register<SoapServices>();
DependencyService.Register<SQLiteHelper>();
DependencyService.Register<BackgroundServiceImplementation>();
DependencyService.Register<PdfService>();
InitApp();
InitLoggerService();
VersionTracking.Track();
MainPage = new RootMasterDetailView();
//DependencyService.Get<ISQLiteHelper>().ImportDatabase("KoreDatabase.db3");
}
//protected override Window CreateWindow(IActivationState activationState)
//{
// MainPage = new RootMasterDetailView();
// return base.CreateWindow(activationState);
//}
private void InitLoggerService()
{
var loggerService = ViewModelLocator.Resolve<ILoggerService>();
loggerService.InitializeAnalytics();
}
private void InitApp()
{
VersionTracking.Track();
Settings.UrlBase = Constants.BaseUrl;
ViewModelLocator.RegisterDependencies();
}
protected override async void OnStart()
{
base.OnStart();
//await InitNavigation(); // ********* WHEN COMMENTED, THE HAMBURGER ICON APPEARES
}
private Task InitNavigation()
{
var navigationService = ViewModelLocator.Resolve<INavigationService>();
return navigationService.InitializeAsync();
}
}
public Task InitializeAsync()
{
if (!Settings.IsLoggedIn)
{
return NavigateToAsync<LoginViewModel>();
}
else
{
if (Settings.FinishedFirstSync)
{
return NavigateToAsync<RootMasterDetailViewModel>();
}
else
{
return NavigateToAsync<StatusViewModel>(true);
}
}
}
public Task NavigateToAsync<TViewModel>() where TViewModel : ViewModelBase
{
return InternalNavigateToAsync(typeof(TViewModel), null);
}
public Task NavigateToAsync<TViewModel>(object parameter) where TViewModel : ViewModelBase
{
return InternalNavigateToAsync(typeof(TViewModel), parameter);
}
private async Task InternalNavigateToAsync(Type viewModelType, object parameter)
{
//_loggerService.RegisterNavigationEvent(viewModelType, parameter);
Page page = CreatePage(viewModelType, parameter);
// if (page is LoginView)
// {
// Application.Current.MainPage = new CustomNavigationView(page);
// }
// else
// {
var navigationPage = Application.Current.MainPage as NavigationPage;
if (navigationPage != null)
{
await navigationPage.PushAsync(page);
}
else
{
Application.Current.MainPage = new NavigationPage(page);
}
// }
await InitializePage(page, parameter);
}
private async Task InitializePage(Page page, object parameter = null)
{
if ((page.BindingContext as ViewModelBase).Initialized)
return;
await (page.BindingContext as ViewModelBase).InitializeAsync(parameter);
if (page is FlyoutPage)
{
await InitializePage(((FlyoutPage)page).Flyout, null);
await InitializePage(((FlyoutPage)page).Detail, null);
}
else if (page is TabbedPage)
{
foreach (var child in (page as TabbedPage).Children)
{
await InitializePage(child, parameter);
}
}
else if (page is NavigationPage)
{
await InitializePage((page as NavigationPage).CurrentPage, null);
}
}
Upvotes: 2
Views: 495
Reputation: 4342
Well, as an answer:
Method1:
Use Shell structure instead of FlyoutPage.
Other way:
Follow up the issue: FlyoutPage inside a NavigationPage causes different behavior between Android and iOS to see if it has any update.
Upvotes: 0