Ejemplo n.º 1
0
        public async Task Navigate(NavigateInfo info)
        {
            if (info?.PageType != null && LockNavigation())
            {
                switch (info.Mode)
                {
                case NavigateMode.Default:
                    CurrentSectionRootPageType = NavigationHelper.GetSectionRootPageTypeForPage(info.PageType);
                    var page = info.CreatePage();
                    await _navigation.PushAsync(page);

                    break;

                case NavigateMode.RemovePrevious:
                case NavigateMode.RemoveAllPrevious:
                    CurrentSectionRootPageType = NavigationHelper.GetSectionRootPageTypeForPage(info.PageType);
                    page = info.CreatePage();
                    await _navigation.PushAsync(page);

                    var numberPagesToRemove = info.Mode == NavigateMode.RemovePrevious ? (int?)(info.NavigateParam as int? ?? 1) : null;
                    while ((numberPagesToRemove == null || numberPagesToRemove > 0) && _navigation.NavigationStack.Count > 1)
                    {
                        _navigation.RemovePage(_navigation.NavigationStack[_navigation.NavigationStack.Count - 2]);
                        if (numberPagesToRemove != null)
                        {
                            numberPagesToRemove--;
                        }
                    }
                    break;

                case NavigateMode.ToSectionRoot:
                    var last = _navigation.NavigationStack.LastOrDefault();
                    if (last == null || last.GetType() != info.PageType)
                    {
                        CurrentSectionRootPageType = info.PageType;

                        page = _navigation.NavigationStack.FirstOrDefault(p => p.GetType() == info.PageType) as BasePage;
                        if (page != null)
                        {
                            var i             = _navigation.NavigationStack.Count - 2;
                            var pageForRemove = _navigation.NavigationStack[i];
                            while (pageForRemove != page)
                            {
                                _navigation.RemovePage(pageForRemove);
                                pageForRemove = _navigation.NavigationStack[--i];
                            }
                            await _navigation.PopAsync();
                        }
                        else
                        {
                            await _navigation.PushAsync(info.CreatePage());
                        }
                    }
                    break;

                case NavigateMode.Modal:
                    var modalPage = info.CreateModalPage();
                    await _navigation.PushModalAsync(modalPage);

                    break;
                }
                UnlockNavigation();
            }
        }
Ejemplo n.º 2
0
 private async void ExecuteNavigateCommand(NavigateInfo info)
 {
     await Navigate(info);
 }