private IGameScreen GetScreenForViewModel(Type viewModelType)
        {
            var viewType = _navigationLookup.GetViewType(viewModelType);

            if (viewType == null)
            {
                throw new NavigationException($"No view is registered for {viewModelType.Name}");
            }

            var view = _serviceLocator.Resolve(viewType);

            if (view == null)
            {
                throw new NavigationException($"No View of type {viewType.Name} has been registered with the Ioc container");
            }

            if (!(view is IGameScreen screen))
            {
                throw new NavigationException($"View type {viewType.Name} is not an IScene");
            }

            return(screen);
        }
        private TPage GetPageForViewModel <TPage>(Type viewModelType) where TPage : Page
        {
            var viewType = _navigationLookup.GetViewType(viewModelType);

            if (viewType == null)
            {
                throw new NavigationException($"No view is registered for {viewModelType.Name}");
            }

            var view = _serviceLocator.Resolve(viewType);

            if (view == null)
            {
                throw new NavigationException($"No View of type {viewType.Name} has been registered with the Ioc container");
            }

            if (!(view is TPage page))
            {
                throw new NavigationException($"View type {viewType.Name} is not a {typeof(TPage).Name}");
            }

            return(page);
        }
        protected BaseTabbedPage(
            TViewModel viewModel,
            INavigationService navigationService,
            INavigationLookup navigationLookup,
            IServiceLocator serviceLocator,
            IAnalyticsService analyticsService)
        {
            ViewModel      = viewModel;
            BindingContext = ViewModel;

            On <Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);

            if (viewModel is ITabbedViewModel _)
            {
                SetBinding(TabDefinitionsProperty, new Binding(nameof(ITabbedViewModel.TabDefinitions), BindingMode.OneWay,
                                                               new ActionConverter <IReadOnlyList <TabDefinition> >(async tabs =>
                {
                    if (tabs == null)
                    {
                        return;
                    }

                    foreach (var tabDefinition in tabs)
                    {
                        if (TabExists(tabDefinition))
                        {
                            analyticsService.Debug("Tab already exists");
                            return;
                        }

                        var viewType = navigationLookup.GetViewType(tabDefinition.ViewModelType);
                        if (viewType == null)
                        {
                            throw new NavigationException($"No view is registered for {tabDefinition.ViewModelType.Name}");
                        }

                        var view = serviceLocator.Resolve(viewType);
                        if (view == null)
                        {
                            throw new NavigationException($"No View of type {viewType.Name} has been registered with the Ioc container");
                        }

                        if (!(view is Page page))
                        {
                            throw new NavigationException($"View type {viewType.Name} is not a {nameof(Page)}");
                        }

                        switch (page.BindingContext)
                        {
                        case IAsyncInitializable initializable:
                            await initializable.InitializeAsync();
                            break;

                        case IInitializingViewModel initializableViewModel:
                            initializableViewModel.InitializeCommand.Execute();
                            break;
                        }

                        if (tabDefinition.NavigationStackName != null)
                        {
                            analyticsService.Debug($"Added new navigating tab for {tabDefinition.ViewModelType.Name}");
                            Children.Add(new NavigationView(navigationService, page, tabDefinition.NavigationStackName)
                            {
                                Title = tabDefinition.Title
                            });
                        }
                        else
                        {
                            analyticsService.Debug($"Added new tab for {tabDefinition.ViewModelType.Name}");
                            page.Title = tabDefinition.Title;
                            Children.Add(page);
                        }
                    }
                })));
            }
        }