[12762] | 1 | using System;
|
---|
| 2 | using System.IO;
|
---|
| 3 | using System.IO.Packaging;
|
---|
| 4 | using System.IO.Compression;
|
---|
| 5 | using System.Linq;
|
---|
| 6 | using System.Text;
|
---|
| 7 | using System.ComponentModel;
|
---|
| 8 | using System.Collections.Generic;
|
---|
| 9 |
|
---|
| 10 | using System.Windows;
|
---|
| 11 | using System.Windows.Controls;
|
---|
| 12 | using System.Windows.Data;
|
---|
| 13 | using System.Windows.Documents;
|
---|
| 14 | using System.Windows.Input;
|
---|
| 15 | using System.Windows.Media;
|
---|
| 16 | using System.Windows.Media.Imaging;
|
---|
| 17 | using System.Windows.Shapes;
|
---|
| 18 | using System.Windows.Xps.Packaging;
|
---|
| 19 |
|
---|
| 20 | namespace WpfTestSvgSample
|
---|
| 21 | {
|
---|
| 22 | /// <summary>
|
---|
| 23 | /// Interaction logic for PrintPreviewWindow.xaml
|
---|
| 24 | /// </summary>
|
---|
| 25 | public partial class PrintPreviewWindow : Window
|
---|
| 26 | {
|
---|
| 27 | #region Private Fields
|
---|
| 28 |
|
---|
| 29 | private string _fileName;
|
---|
| 30 | private Package _xpsDocPackage;
|
---|
| 31 | private XpsDocument _xpsDocument;
|
---|
| 32 |
|
---|
| 33 | #endregion
|
---|
| 34 |
|
---|
| 35 | #region Constructors and Destructor
|
---|
| 36 |
|
---|
| 37 | public PrintPreviewWindow()
|
---|
| 38 | {
|
---|
| 39 | InitializeComponent();
|
---|
| 40 |
|
---|
| 41 | this.Loaded += new RoutedEventHandler(OnWindowLoaded);
|
---|
| 42 | this.Unloaded += new RoutedEventHandler(OnWindowUnloaded);
|
---|
| 43 |
|
---|
| 44 | this.Closed += new EventHandler(OnWindowClosed);
|
---|
| 45 | this.Closing += new CancelEventHandler(OnWindowClosing);
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | #endregion
|
---|
| 49 |
|
---|
| 50 | #region Public Methods
|
---|
| 51 |
|
---|
| 52 | public void LoadDocument(XpsDocument document, Package package, string sourceFileName)
|
---|
| 53 | {
|
---|
| 54 | if (document == null)
|
---|
| 55 | {
|
---|
| 56 | return;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | try
|
---|
| 60 | {
|
---|
| 61 | if (_xpsDocument != null)
|
---|
| 62 | {
|
---|
| 63 | _xpsDocument.Close();
|
---|
| 64 | _xpsDocument = null;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | if (_xpsDocPackage != null)
|
---|
| 68 | {
|
---|
| 69 | _xpsDocPackage.Close();
|
---|
| 70 | _xpsDocPackage = null;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | if (!String.IsNullOrEmpty(_fileName))
|
---|
| 74 | {
|
---|
| 75 | PackageStore.RemovePackage(new Uri(_fileName));
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | catch
|
---|
| 79 | {
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | _xpsDocument = document;
|
---|
| 83 | _xpsDocPackage = package;
|
---|
| 84 | _fileName = sourceFileName;
|
---|
| 85 |
|
---|
| 86 | docViewer.Document = _xpsDocument.GetFixedDocumentSequence();
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | #endregion
|
---|
| 90 |
|
---|
| 91 | #region Private Methods
|
---|
| 92 |
|
---|
| 93 | private void OnWindowLoaded(object sender, RoutedEventArgs e)
|
---|
| 94 | {
|
---|
| 95 | ContentControl findToolbar = docViewer.Template.FindName(
|
---|
| 96 | "PART_FindToolBarHost", docViewer) as ContentControl;
|
---|
| 97 | if (findToolbar != null)
|
---|
| 98 | {
|
---|
| 99 | findToolbar.Visibility = Visibility.Collapsed;
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | private void OnWindowUnloaded(object sender, RoutedEventArgs e)
|
---|
| 104 | {
|
---|
| 105 | try
|
---|
| 106 | {
|
---|
| 107 | docViewer.Document = null;
|
---|
| 108 |
|
---|
| 109 | if (_xpsDocument != null)
|
---|
| 110 | {
|
---|
| 111 | _xpsDocument.Close();
|
---|
| 112 | _xpsDocument = null;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | if (_xpsDocPackage != null)
|
---|
| 116 | {
|
---|
| 117 | _xpsDocPackage.Close();
|
---|
| 118 | _xpsDocPackage = null;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | if (!String.IsNullOrEmpty(_fileName))
|
---|
| 122 | {
|
---|
| 123 | PackageStore.RemovePackage(new Uri(_fileName));
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
| 126 | catch
|
---|
| 127 | {
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | private void OnWindowClosing(object sender, CancelEventArgs e)
|
---|
| 132 | {
|
---|
| 133 | try
|
---|
| 134 | {
|
---|
| 135 | docViewer.Document = null;
|
---|
| 136 |
|
---|
| 137 | if (_xpsDocument != null)
|
---|
| 138 | {
|
---|
| 139 | _xpsDocument.Close();
|
---|
| 140 | _xpsDocument = null;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | if (_xpsDocPackage != null)
|
---|
| 144 | {
|
---|
| 145 | _xpsDocPackage.Close();
|
---|
| 146 | _xpsDocPackage = null;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | if (!String.IsNullOrEmpty(_fileName))
|
---|
| 150 | {
|
---|
| 151 | PackageStore.RemovePackage(new Uri(_fileName));
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
| 154 | catch
|
---|
| 155 | {
|
---|
| 156 | }
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | private void OnWindowClosed(object sender, EventArgs e)
|
---|
| 160 | {
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | #endregion
|
---|
| 164 | }
|
---|
| 165 | }
|
---|