Esempio n. 1
0
        private Page ResolveTabbedPageForViewModels(ITabbedViewModel tabbedViewModel, Type[] types, object args = null)
        {
            var tabbedPage = new BaseTabbedPage {
                BindingContext = tabbedViewModel
            };

            // tabbedPage.SelectedColor = Color.FromHex("#B68024");
            tabbedPage.BarBackgroundColor = Color.Black;
            tabbedPage.BarTextColor       = Color.FromHex("#B68024");
            tabbedPage.On <Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
            tabbedPage.On <Android>().SetBarSelectedItemColor(Color.FromHex("#B68024"));
            tabbedPage.On <Android>().SetBarItemColor(Color.White);
            tabbedPage.BindViewModel(tabbedViewModel);

            foreach (var type in types)
            {
                var childPage = ResolvePageAndViewModel(type, args);

                if (!(childPage.BindingContext is BaseViewModel childViewModel))
                {
                    throw new Exception("Tabbed Page BindingContext must be as ViewModel type");
                }
                var newNavicationPage = new BaseNavigationPage(childPage, false);
                newNavicationPage.Icon = childPage.Icon;

                childViewModel.ParentViewModel = tabbedViewModel;
                tabbedViewModel.ChildViewModels.Add(type.Name, childViewModel);

                tabbedPage.Children.Add(newNavicationPage);
            }

            tabbedViewModel.SelectedPageChange += (s, e) =>
            {
                foreach (var p in tabbedPage.Children)
                {
                    if (p.BindingContext.GetType() == e.SelectedViewModelType)
                    {
                        tabbedPage.CurrentPage = p;
                        break;
                    }
                }
            };

            tabbedPage.Title = tabbedPage.Children[0].Title;
            tabbedPage.CurrentPageChanged += (sender, eventArgs) =>
            {
                tabbedPage.Title = tabbedPage.CurrentPage.Title;
                var current = tabbedPage.CurrentPage.Navigation.NavigationStack;
                tabbedViewModel.OnSelectedTabChanged((BaseViewModel)tabbedPage.CurrentPage.BindingContext);
                NavigationService.Navigation = tabbedPage.CurrentPage.Navigation;
            };

            return(tabbedPage);
        }
Esempio n. 2
0
        private Page ResolveTabbedPageForViewModels(ITabbedViewModel tabbedViewModel, Type[] types, object args = null)
        {
            var tabbedPage = new BaseTabbedPage {
                BindingContext = tabbedViewModel
            };

            tabbedPage.BindViewModel(tabbedViewModel);

            foreach (var type in types)
            {
                var childPage = ResolvePageAndViewModel(type, args);

                if (!(childPage.BindingContext is BaseViewModel childViewModel))
                {
                    throw new Exception("Tabbed Page BindingContext must be as ViewModel type");
                }

                childViewModel.ParentViewModel = tabbedViewModel;
                tabbedViewModel.ChildViewModels.Add(type.Name, childViewModel);

                tabbedPage.Children.Add(childPage);
            }

            tabbedViewModel.SelectedPageChange += (s, e) =>
            {
                foreach (var p in tabbedPage.Children)
                {
                    if (p.BindingContext.GetType() == e.SelectedViewModelType)
                    {
                        tabbedPage.CurrentPage = p;
                        break;
                    }
                }
            };

            tabbedPage.Title = tabbedPage.Children[0].Title;
            tabbedPage.CurrentPageChanged += (sender, eventArgs) =>
            {
                tabbedPage.Title = tabbedPage.CurrentPage.Title;
                tabbedViewModel.OnSelectedTabChanged((BaseViewModel)tabbedPage.CurrentPage.BindingContext);
            };

            return(tabbedPage);
        }