/// <summary> /// Add an imported page to our output /// @throws IOException, BadPdfFormatException /// </summary> /// <param name="iPage">an imported page</param> public void AddPage(PdfImportedPage iPage) { var pageNum = SetFromIPage(iPage); var thePage = Reader.GetPageN(pageNum); var origRef = Reader.GetPageOrigRef(pageNum); Reader.ReleasePage(pageNum); var key = new RefKey(origRef); PdfIndirectReference pageRef; var iRef = (IndirectReferences)Indirects[key]; if (iRef != null && !iRef.Copied) { PageReferences.Add(iRef.Ref); iRef.SetCopied(); } pageRef = CurrentPage; if (iRef == null) { iRef = new IndirectReferences(pageRef); Indirects[key] = iRef; } iRef.SetCopied(); var newPage = CopyDictionary(thePage); Root.AddPage(newPage); ++currentPageNumber; }
protected void OnPopToNewRoot(IPageViewModel viewModel, bool animated) { var pref = createPageFor(viewModel); PageReferences.Clear(); PageReferences.Add(pref); popToNewRootAsync(pref.View, animated); }
protected virtual void OnPushViewModel(IPageViewModel viewModel, bool animated) { if (PageReferences.Any(p => p.Model == viewModel)) { throw new Exception(String.Format("The navigation stack already contains the viewModel: {0}", viewModel)); } var pref = createPageFor(viewModel); PageReferences.Add(pref); PushAsync(pref.View, animated); }
async void updatePages() { if (_pages != null && _pages.Count > 0) { foreach (var pref in PageReferences.Where(p => !_pages.Contains(p.Model)).ToList()) { PageReferences.Remove(pref); } if (new[] { this.Navigation.NavigationStack.FirstOrDefault(), this.Navigation.NavigationStack.LastOrDefault(), PageReferences.LastOrDefault()?.View } .All(v => v == PageReferences.FirstOrDefault()?.View)) { OnPopToRoot(Pages.LastOrDefault(), TransitionAnimationEnabled); } else { if (Navigation.NavigationStack.Count > 0) { var pref = createPageFor(Pages.LastOrDefault()); PageReferences.Clear(); PageReferences.Add(pref); await popToNewRootAsync(pref.View, TransitionAnimationEnabled); } else { OnPushViewModel(Pages.LastOrDefault(), TransitionAnimationEnabled); } } } else { //At least on page should be displayed PageReferences.Clear(); var blankPage = new ContentPage { BackgroundColor = Color.Transparent }; if (Navigation.NavigationStack.Count > 0) { await popToNewRootAsync(blankPage, TransitionAnimationEnabled); } else { await PushAsync(blankPage, TransitionAnimationEnabled); } } }