示例#1
0
 private void SelectChapter(ChapterViewModel chapterViewModel)
 {
     if (string.IsNullOrEmpty(chapterViewModel.HtmlId))
     {
         bool samePage = false;
         if (selectedChapter != null)
         {
             selectedChapter.IsSelected = false;
             if (selectedChapter == chapterViewModel || (!string.IsNullOrEmpty(selectedChapter.HtmlId) && chapterViewModel.ParentChapter == selectedChapter))
             {
                 selectedChapter        = null;
                 selectedChapterContent = null;
                 samePage = true;
             }
         }
         selectedChapter = chapterViewModel;
         selectedChapter.IsTreeItemExpanded = true;
         selectedChapter.IsSelected         = true;
         SelectedChapterContent             = new ChapterContentViewModel(selectedChapter.HtmlContent, images, styleSheets, fonts);
         if (BookView.View != null && samePage)
         {
             BookView.View.ScrollTo("");
         }
     }
     else
     {
         if (selectedChapter == null)
         {
             selectedChapter = chapterViewModel.ParentChapter;
         }
         else
         {
             selectedChapter.IsSelected = false;
         }
         selectedChapter = chapterViewModel;
         selectedChapter.IsTreeItemExpanded = true;
         selectedChapter.IsSelected         = true;
         if (SelectedChapterContent.HtmlContent != chapterViewModel.ParentChapter.HtmlContent)
         {
             SelectedChapterContent = new ChapterContentViewModel(chapterViewModel.ParentChapter.HtmlContent, images, styleSheets, fonts);
         }
         Task.Run(async() =>
         {
             await Task.Delay(100);
             if (BookView.View != null)
             {
                 BookView.View.ScrollTo(chapterViewModel.HtmlId);
             }
         });
         // SelectedElement = chapterViewModel.HtmlContent;
     }
 }
示例#2
0
        public void LoadBook(int bookId, bool append = false)
        {
            var epubBook = bookModel.OpenBook(bookId);

            Contents    = Contents.AddRange(bookModel.GetChapters(epubBook));
            images      = images.AddRange(epubBook.Content.Images.ToDictionary(imageFile => imageFile.Key, imageFile => imageFile.Value.Content));
            styleSheets = styleSheets.AddRange(epubBook.Content.Css.ToDictionary(cssFile => cssFile.Key, cssFile => cssFile.Value.Content));
            fonts       = fonts.AddRange(epubBook.Content.Fonts.ToDictionary(fontFile => fontFile.Key, fontFile => fontFile.Value.Content));

            selectChapterCommand   = null;
            selectedChapter        = null;
            selectedChapterContent = null;
            if (Contents.Any())
            {
                SelectChapter(Contents.First());
            }
        }