private void Click_Tool_DisplayBookmark(object sender, RoutedEventArgs e) { try { if (showBookMarks != null) { return; } if (templatePath != String.Empty && wordDoc != null) { int id = 1; myBookMarks.Clear(); foreach (MsWord.Bookmark bk in wordDoc.Bookmarks) { myBookMarks.Add(new CurrentBookMark { Id = id, Name = bk.Name }); id++; } showBookMarks = new ShowBookMarks(); showBookMarks.Owner = this; showBookMarks.BookMarks_DataGrid.ItemsSource = myBookMarks; showBookMarks.ReturnBookMarks += new ShowBookMarks.ReturnBookMarksEventHandle(HandleReturnBookMarksEvent); showBookMarks.DeleteAllBookMarks += new ShowBookMarks.DeleteAllDocumentBookMarksEventHandle(HandleDeleteAllBookMarks); showBookMarks.Closed += new EventHandler(HandleShowBookMarksWindowClosed); if (myBookMarks.Count == 0) { showBookMarks.TextBlock_BookMarks.Text = "当前文档不存在书签"; } showBookMarks.Show(); } else { MessageBox.Show("未加载模板,请先打开Word模板", "SC-Information"); } } catch (Exception ex) { MessageBox.Show("错误信息:\n" + ex.Message + "\nSource:" + ex.Source + "\nTrace:" + ex.StackTrace); } }
private void HandleShowBookMarksWindowClosed(object sender, EventArgs e) { showBookMarks = null; }