BackgroundCreateFileContentViewModel.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit.PDFPage;
  3. using ComPDFKitViewer.PdfViewer;
  4. using PDF_Office.EventAggregators;
  5. using PDF_Office.Helper;
  6. using PDF_Office.Model;
  7. using PDF_Office.Model.EditTools.Background;
  8. using PDF_Office.Model.EditTools.Watermark;
  9. using PDF_Office.Properties;
  10. using PDFSettings;
  11. using Prism.Commands;
  12. using Prism.Events;
  13. using Prism.Mvvm;
  14. using Prism.Regions;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Drawing.Printing;
  18. using System.IO;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. using System.Windows;
  23. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrayNotify;
  24. namespace PDF_Office.ViewModels.EditTools.Background
  25. {
  26. public class BackgroundCreateFileContentViewModel : BindableBase, INavigationAware
  27. {
  28. IEventAggregator eventAggregator;
  29. private BackgroundItem TemplateBackgroundItem;
  30. public BackgroundInfo BackgroundInfo = new BackgroundInfo();
  31. private CPDFViewer PDFViewer;
  32. private List<string> _rotationList = new List<string>();
  33. public List<string> RotationList
  34. {
  35. get { return _rotationList; }
  36. set { SetProperty(ref _rotationList, value); }
  37. }
  38. private List<string> _opacityList = new List<string>();
  39. public List<string> OpacityList
  40. {
  41. get { return _opacityList; }
  42. set
  43. {
  44. SetProperty(ref _opacityList, value);
  45. }
  46. }
  47. private List<string> _relativeRatioList = new List<string>();
  48. public List<string> RelativeRatioList
  49. {
  50. get { return _relativeRatioList; }
  51. set
  52. {
  53. SetProperty(ref _relativeRatioList, value);
  54. }
  55. }
  56. private int _rotationValue = 0;
  57. public int RotationValue
  58. {
  59. get { return _rotationValue; }
  60. set
  61. {
  62. SetProperty(ref _rotationValue, value);
  63. BackgroundInfo.Rotation = value;
  64. eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
  65. {
  66. Unicode = Unicode,
  67. Status = BackgroundInfo
  68. });
  69. }
  70. }
  71. private int _opacityValue = 100;
  72. public int OpacityValue
  73. {
  74. get { return _opacityValue; }
  75. set
  76. {
  77. SetProperty(ref _opacityValue, value);
  78. BackgroundInfo.Opacity = (byte)(value);
  79. eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
  80. {
  81. Unicode = Unicode,
  82. Status = BackgroundInfo
  83. });
  84. }
  85. }
  86. private int _relativeRatioValue = 50;
  87. public int RelativeRatioValue
  88. {
  89. get { return _relativeRatioValue; }
  90. set
  91. {
  92. SetProperty(ref _rotationValue, value);
  93. BackgroundInfo.Scale = value;
  94. eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
  95. {
  96. Unicode = Unicode,
  97. Status = BackgroundInfo
  98. });
  99. }
  100. }
  101. private string _verticalOffsetValue = "0";
  102. public string VerticalOffsetValue
  103. {
  104. get { return _verticalOffsetValue; }
  105. set
  106. {
  107. SetProperty(ref _verticalOffsetValue, value);
  108. BackgroundInfo.VertOffset = float.Parse(VerticalOffsetValue);
  109. eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
  110. {
  111. Unicode = Unicode,
  112. Status = BackgroundInfo
  113. });
  114. }
  115. }
  116. private string _relativeScaleText = "50 %";
  117. public string RelativeScaleText
  118. {
  119. get { return _relativeScaleText; }
  120. set
  121. {
  122. SetProperty(ref _relativeScaleText, value);
  123. eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
  124. {
  125. Unicode = Unicode,
  126. Status = BackgroundInfo
  127. });
  128. }
  129. }
  130. private string _horizOffsetValue = "0";
  131. public string HorizontalOffsetValue
  132. {
  133. get { return _horizOffsetValue; }
  134. set
  135. {
  136. SetProperty(ref _horizOffsetValue, value);
  137. BackgroundInfo.HorizOffset = float.Parse(HorizontalOffsetValue);
  138. eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
  139. {
  140. Unicode = Unicode,
  141. Status = BackgroundInfo
  142. });
  143. }
  144. }
  145. private string _rotationText = "0";
  146. public string RotationText
  147. {
  148. get { return _rotationText; }
  149. set
  150. {
  151. SetProperty(ref _rotationText, value);
  152. }
  153. }
  154. private string _opacityText = "100 %";
  155. public string OpacityText
  156. {
  157. get { return _opacityText; }
  158. set
  159. {
  160. SetProperty(ref _opacityText, value);
  161. }
  162. }
  163. private ObservableDictionary<string, bool> _getLocationFromNumber = new ObservableDictionary<string, bool>();
  164. public ObservableDictionary<string, bool> GetLocationFromNumber
  165. {
  166. get { return _getLocationFromNumber; }
  167. }
  168. private string _fileNameText = "";
  169. public string FileNameText
  170. {
  171. get { return _fileNameText; }
  172. set
  173. {
  174. SetProperty(ref _fileNameText, value);
  175. }
  176. }
  177. private bool isFirstEnter = true;
  178. public bool IsFirstEnter
  179. {
  180. get => isFirstEnter;
  181. set => isFirstEnter = value;
  182. }
  183. private Visibility _createModFileVisible = Visibility.Collapsed;
  184. public Visibility CreateModFileVisible
  185. {
  186. get => _createModFileVisible;
  187. set => SetProperty(ref _createModFileVisible, value);
  188. }
  189. private bool _isRelativeScaleValue = false;
  190. public bool IsRelativeScaleValue
  191. {
  192. get { return _isRelativeScaleValue; }
  193. set
  194. {
  195. SetProperty(ref _isRelativeScaleValue, value);
  196. BackgroundInfo.IsRelativeScale = IsRelativeScaleValue;
  197. eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
  198. {
  199. Unicode = Unicode,
  200. Status = BackgroundInfo
  201. });
  202. }
  203. }
  204. public DelegateCommand OpenFileCommand { get; set; }
  205. public DelegateCommand<object> ChangeLocationCommand { get; set; }
  206. public string unicode = null;
  207. public string Unicode = null;
  208. public BackgroundCreateFileContentViewModel(IEventAggregator eventAggregator)
  209. {
  210. this.eventAggregator = eventAggregator;
  211. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  212. BackgroundInfo.BackgroundType = C_Background_Type.BG_TYPE_IMAGE;
  213. ChangeLocationCommand = new DelegateCommand<object>(ChangeLocation);
  214. InitComponent();
  215. BackgroundInfo.Horizalign = C_Background_Horizalign.BG_HORIZALIGN_CENTER;
  216. BackgroundInfo.Vertalign = C_Background_Vertalign.BG_VERTALIGN_CENTER;
  217. InitLocationButtonMatrix();
  218. OpenFileCommand = new DelegateCommand(OpenFile);
  219. eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Subscribe(SaveBackgroundTemplate, e => e.Unicode == Unicode);
  220. eventAggregator.GetEvent<ConfirmEditBackgroundTemplateItemEvent>().Subscribe(ConfirmEditBackgroundTemplateItem, e => e.Unicode == Unicode);
  221. }
  222. public string _pageRangeText { get; set; } = "0";
  223. public string PageRangeText
  224. {
  225. get { return _pageRangeText; }
  226. set
  227. {
  228. _pageRangeText = value;
  229. EditToolsHelper.GetPageRange(PageRangeSelectIndex, PDFViewer.Document, ref BackgroundInfo.PageRange, PageRangeText);
  230. eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode { Unicode=Unicode,Status=BackgroundInfo});
  231. }
  232. }
  233. private int maxPageRange = 0;
  234. public int MaxPageRange
  235. {
  236. get { return maxPageRange; }
  237. set
  238. {
  239. SetProperty(ref maxPageRange, value);
  240. }
  241. }
  242. private int _pageRangeSelectIndex = 0;
  243. public int PageRangeSelectIndex
  244. {
  245. get { return _pageRangeSelectIndex; }
  246. set
  247. {
  248. SetProperty(ref _pageRangeSelectIndex, value);
  249. EditToolsHelper.GetPageRange(PageRangeSelectIndex, PDFViewer.Document, ref BackgroundInfo.PageRange, PageRangeText);
  250. }
  251. }
  252. public void InitComponent()
  253. {
  254. InitOpacityList();
  255. InitRotationList();
  256. InitRelativeRatioList();
  257. }
  258. private void InitRotationList()
  259. {
  260. RotationList.Clear();
  261. for (int defaultRotation = -45; defaultRotation <= 45; defaultRotation += 15)
  262. {
  263. RotationList.Add(defaultRotation.ToString());
  264. }
  265. }
  266. private void InitOpacityList()
  267. {
  268. OpacityList.Clear();
  269. for (int defaultOpacity = 10; defaultOpacity <= 100; defaultOpacity += 10)
  270. {
  271. OpacityList.Add(defaultOpacity.ToString() + " %");
  272. }
  273. }
  274. private void InitRelativeRatioList()
  275. {
  276. RelativeRatioList.Clear();
  277. for (int defaultRelativeRatioList = 10; defaultRelativeRatioList <= 100; defaultRelativeRatioList += 10)
  278. {
  279. RelativeRatioList.Add(defaultRelativeRatioList.ToString() + " %");
  280. }
  281. }
  282. private void InitLocationButtonMatrix()
  283. {
  284. GetLocationFromNumber.Clear();
  285. for (var temp = 0; temp <= 22; temp++)
  286. {
  287. GetLocationFromNumber.Add(temp.ToString(), true);
  288. if (temp % 10 == 2)
  289. {
  290. temp += 7;
  291. }
  292. }
  293. int Num = (int)BackgroundInfo.Vertalign * 10 + (int)BackgroundInfo.Horizalign;
  294. GetLocationFromNumber[Num.ToString()] = false;
  295. }
  296. public void InitComponentBySelectedInfo()
  297. {
  298. ConvertItemToInfo(TemplateBackgroundItem, ref BackgroundInfo);
  299. RotationText = BackgroundInfo.Rotation.ToString();
  300. OpacityText = BackgroundInfo.Opacity.ToString();
  301. InitLocationButtonMatrix();
  302. IsRelativeScaleValue = BackgroundInfo.IsRelativeScale;
  303. RelativeScaleText = BackgroundInfo.Scale.ToString();
  304. HorizontalOffsetValue = (BackgroundInfo.HorizOffset).ToString();
  305. VerticalOffsetValue = (BackgroundInfo.VertOffset).ToString();
  306. PageRangeSelectIndex = BackgroundInfo.PageRangeIndex;
  307. }
  308. public void ChangeLocation(object e)
  309. {
  310. string args = e as string;
  311. if (args != null)
  312. {
  313. BackgroundInfo.Vertalign = (C_Background_Vertalign)(int.Parse(args) / 10);
  314. BackgroundInfo.Horizalign = (C_Background_Horizalign)(int.Parse(args) % 10);
  315. eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
  316. {
  317. Unicode = Unicode,
  318. Status = BackgroundInfo
  319. });
  320. InitLocationButtonMatrix();
  321. }
  322. }
  323. public void OpenFile()
  324. {
  325. System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
  326. dlg.Multiselect = false;
  327. dlg.Filter = "PDF|*.png;*.jpg;*.pdf";
  328. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  329. {
  330. FileNameText = dlg.SafeFileName;
  331. FileInfo file = new FileInfo(dlg.FileName);
  332. if (file.Extension == ".pdf")
  333. {
  334. GetBitmapFromDocment(dlg.FileName);
  335. }
  336. else
  337. {
  338. EditToolsHelper.ChooseFile(dlg.FileName, ref BackgroundInfo);
  339. }
  340. CreateModFileVisible = Visibility.Visible;
  341. eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
  342. {
  343. Unicode = Unicode,
  344. Status = BackgroundInfo
  345. });
  346. }
  347. }
  348. public async void GetBitmapFromDocment(string filePath)
  349. {
  350. CPDFDocument document = CPDFDocument.InitWithFilePath(filePath);
  351. CPDFPage page = document.PageAtIndex(0);
  352. byte[] bmp_data = new byte[(int)page.PageSize.Width * (int)page.PageSize.Height * 4];
  353. await Task.Run(delegate
  354. {
  355. page.RenderPageBitmap(0, 0, (int)page.PageSize.Width, (int)page.PageSize.Height, 0xffffffff, bmp_data, 1);
  356. });
  357. BackgroundInfo.ImageArray = bmp_data;
  358. BackgroundInfo.ImageWidth = (int)page.PageSize.Width;
  359. BackgroundInfo.ImageHeight = (int)page.PageSize.Height;
  360. document.ReleasePages();
  361. document.Release();
  362. }
  363. public void ConvertItemToInfo(BackgroundItem backgroundItem, ref BackgroundInfo backgroundInfo)
  364. {
  365. if (backgroundItem != null)
  366. {
  367. backgroundInfo.BackgroundType = C_Background_Type.BG_TYPE_IMAGE;
  368. backgroundInfo.Color = backgroundItem.bgColor;
  369. backgroundInfo.Horizalign = backgroundItem.horizalign;
  370. backgroundInfo.Vertalign = backgroundItem.vertalign;
  371. backgroundInfo.VertOffset = backgroundItem.vertOffset;
  372. backgroundInfo.Horizalign = backgroundItem.horizalign;
  373. backgroundInfo.Opacity = backgroundItem.opacity;
  374. backgroundInfo.Rotation = backgroundItem.rotation;
  375. backgroundInfo.IsRelativeScale = backgroundItem.isRelativeScale;
  376. backgroundInfo.Scale = backgroundItem.scale;
  377. backgroundInfo.PageRangeIndex = backgroundItem.PageRangeIndex;
  378. backgroundInfo.PageRange = backgroundItem.pageRange;
  379. }
  380. }
  381. public void ConvertInfoToItem(ref BackgroundItem backgroundItem, BackgroundInfo backgroundInfo)
  382. {
  383. backgroundItem.type = C_Background_Type.BG_TYPE_IMAGE;
  384. backgroundItem.imageArray = backgroundInfo.ImageArray;
  385. backgroundItem.imageWidth = backgroundInfo.ImageWidth;
  386. backgroundItem.imageHeight = backgroundInfo.ImageHeight;
  387. backgroundItem.horizalign = backgroundInfo.Horizalign;
  388. backgroundItem.vertalign = backgroundInfo.Vertalign;
  389. backgroundItem.vertOffset = backgroundInfo.VertOffset;
  390. backgroundItem.horizalign = backgroundInfo.Horizalign;
  391. backgroundItem.opacity = backgroundInfo.Opacity;
  392. backgroundItem.rotation = backgroundInfo.Rotation;
  393. backgroundItem.isRelativeScale = backgroundInfo.IsRelativeScale;
  394. backgroundItem.scale = backgroundInfo.Scale;
  395. //backgroundItem.pagRangeMode = backgroundInfo.PageRange;
  396. }
  397. public void SaveCurrentTemplate()
  398. {
  399. var backgroundItem = new BackgroundItem();
  400. ConvertInfoToItem(ref backgroundItem, BackgroundInfo);
  401. backgroundItem.templateName += Settings.Default.BackgroundIndex.ToString();
  402. try
  403. {
  404. //创建缓存文件夹
  405. string folderPath = Path.Combine(App.CurrentPath, "Background");
  406. //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除同名文件
  407. //保险措施(猜测)
  408. if (File.Exists(folderPath))
  409. {
  410. File.Delete(folderPath);
  411. }
  412. DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
  413. if (!tempfolder.Exists)
  414. {
  415. tempfolder.Create();
  416. }
  417. //预览图缓存
  418. string saveName = Guid.NewGuid().ToString();
  419. string savePath = Path.Combine(folderPath, saveName);
  420. System.Windows.Size pageSize = PDFViewer.Document.GetPageSize(0);
  421. CPDFDocument tempDocument = CPDFDocument.CreateDocument();
  422. if (tempDocument != null)
  423. {
  424. tempDocument.InsertPage(0, pageSize.Width, pageSize.Height, null);
  425. var tempBackground = tempDocument.GetBackground();
  426. tempBackground.SetBackgroundType(BackgroundInfo.BackgroundType);
  427. tempBackground.SetImage(BackgroundInfo.ImageArray, BackgroundInfo.ImageWidth, BackgroundInfo.ImageHeight, ComPDFKit.Import.C_Scale_Type.fitCenter);
  428. if (!BackgroundInfo.IsRelativeScale)
  429. {
  430. tempBackground.SetScale(1);
  431. }
  432. else
  433. {
  434. tempBackground.SetScale(BackgroundInfo.Scale/100);
  435. }
  436. tempBackground.SetRotation((float)((BackgroundInfo.Rotation / 180) * Math.PI));
  437. tempBackground.SetOpacity((byte)((float)(BackgroundInfo.Opacity / 100) * 255));
  438. tempBackground.SetVertalign(BackgroundInfo.Vertalign);
  439. tempBackground.SetHorizalign(BackgroundInfo.Horizalign);
  440. tempBackground.SetXOffset(BackgroundInfo.HorizOffset);
  441. tempBackground.SetYOffset(BackgroundInfo.VertOffset);
  442. tempBackground.SetPages("0");
  443. tempBackground.SetAllowsPrint(true);
  444. tempBackground.SetAllowsView(true);
  445. tempBackground.Update();
  446. //获取透明背景的图片
  447. var bitmap = ToolMethod.RenderPageBitmapNoWait(tempDocument, (int)pageSize.Width, (int)pageSize.Height, 0, false, false, 0x00FFFFFF);
  448. using (FileStream stream = new FileStream(savePath, FileMode.Create))
  449. {
  450. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  451. }
  452. backgroundItem.previewImagePath = savePath;
  453. tempDocument.Release();
  454. Settings.Default.BackgroundTemplateList.Add(backgroundItem);
  455. Settings.Default.Save();
  456. }
  457. }
  458. catch
  459. {
  460. }
  461. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
  462. {
  463. Unicode = Unicode,
  464. Status = EnumTemplateListOrCreate.StatusTemplate
  465. });
  466. }
  467. public void ConfirmEditBackgroundTemplateItem(EnumColorOrFileUnicode enumColorOrFileunicode)
  468. {
  469. EnumColorOrFile enumColorOrFile = enumColorOrFileunicode.Status;
  470. if (enumColorOrFile == EnumColorOrFile.StatusFile)
  471. {
  472. var backgroundItem = new BackgroundItem();
  473. ConvertInfoToItem(ref backgroundItem, BackgroundInfo);
  474. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode { Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusTemplate });
  475. try
  476. {
  477. //创建缓存文件夹
  478. string folderPath = Path.Combine(App.CurrentPath, "Background");
  479. //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除同名文件
  480. //保险措施(猜测)
  481. if (File.Exists(folderPath))
  482. {
  483. File.Delete(folderPath);
  484. }
  485. DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
  486. if (!tempfolder.Exists)
  487. {
  488. tempfolder.Create();
  489. }
  490. //预览图缓存
  491. string saveName = Guid.NewGuid().ToString();
  492. string savePath = Path.Combine(folderPath, saveName);
  493. System.Windows.Size pageSize = PDFViewer.Document.GetPageSize(0);
  494. CPDFDocument tempDocument = CPDFDocument.CreateDocument();
  495. if (tempDocument != null)
  496. {
  497. tempDocument.InsertPage(0, pageSize.Width, pageSize.Height, null);
  498. var tempBackground = tempDocument.GetBackground();
  499. tempBackground.SetBackgroundType(BackgroundInfo.BackgroundType);
  500. tempBackground.SetImage(BackgroundInfo.ImageArray, BackgroundInfo.ImageWidth, BackgroundInfo.ImageHeight, ComPDFKit.Import.C_Scale_Type.fitCenter);
  501. if (!BackgroundInfo.IsRelativeScale)
  502. {
  503. tempBackground.SetScale(1);
  504. }
  505. else
  506. {
  507. tempBackground.SetScale(BackgroundInfo.Scale/100);
  508. }
  509. tempBackground.SetRotation((float)((BackgroundInfo.Rotation / 180) * Math.PI));
  510. tempBackground.SetOpacity((byte)((float)(BackgroundInfo.Opacity / 100) * 255));
  511. tempBackground.SetVertalign(BackgroundInfo.Vertalign);
  512. tempBackground.SetHorizalign(BackgroundInfo.Horizalign);
  513. tempBackground.SetXOffset(BackgroundInfo.HorizOffset);
  514. tempBackground.SetYOffset(BackgroundInfo.VertOffset);
  515. tempBackground.SetPages("0");
  516. tempBackground.SetAllowsPrint(true);
  517. tempBackground.SetAllowsView(true);
  518. tempBackground.Update();
  519. //获取透明背景的图片
  520. var bitmap = ToolMethod.RenderPageBitmapNoWait(tempDocument, (int)pageSize.Width, (int)pageSize.Height, 0, false, false, 0x00FFFFFF);
  521. using (FileStream stream = new FileStream(savePath, FileMode.Create))
  522. {
  523. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  524. }
  525. backgroundItem.previewImagePath = savePath;
  526. tempDocument.Release();
  527. Settings.Default.BackgroundTemplateList[TemplateBackgroundItem.listIndex] = backgroundItem;
  528. Settings.Default.Save();
  529. }
  530. }
  531. catch
  532. {
  533. }
  534. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
  535. {
  536. Unicode = Unicode,
  537. Status = EnumTemplateListOrCreate.StatusTemplate
  538. });
  539. }
  540. }
  541. public void SaveBackgroundTemplate(EnumColorOrFileUnicode enumColorOrFileunicode)
  542. {
  543. EnumColorOrFile enumColorOrFile = enumColorOrFileunicode.Status;
  544. if (enumColorOrFile == EnumColorOrFile.StatusFile)
  545. {
  546. SaveCurrentTemplate();
  547. }
  548. }
  549. public bool IsNavigationTarget(NavigationContext navigationContext)
  550. {
  551. return true;
  552. }
  553. public void OnNavigatedFrom(NavigationContext navigationContext)
  554. {
  555. }
  556. public void OnNavigatedTo(NavigationContext navigationContext)
  557. {
  558. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  559. MaxPageRange = PDFViewer.Document.PageCount;
  560. EditToolsHelper.GetPageRange(PageRangeSelectIndex, PDFViewer.Document, ref BackgroundInfo.PageRange, PageRangeText);
  561. navigationContext.Parameters.TryGetValue<string>("UniCode", out unicode);
  562. if (navigationContext.Parameters.TryGetValue<BackgroundItem>("BackgroundItem", out TemplateBackgroundItem))
  563. {
  564. InitComponentBySelectedInfo();
  565. }
  566. }
  567. }
  568. }