BackgroundCreateFileContentViewModel.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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 _pageRangeSelectIndex = 0;
  234. public int PageRangeSelectIndex
  235. {
  236. get { return _pageRangeSelectIndex; }
  237. set
  238. {
  239. SetProperty(ref _pageRangeSelectIndex, value);
  240. EditToolsHelper.GetPageRange(PageRangeSelectIndex, PDFViewer.Document, ref BackgroundInfo.PageRange, PageRangeText);
  241. }
  242. }
  243. public void InitComponent()
  244. {
  245. InitOpacityList();
  246. InitRotationList();
  247. InitRelativeRatioList();
  248. }
  249. private void InitRotationList()
  250. {
  251. RotationList.Clear();
  252. for (int defaultRotation = -45; defaultRotation <= 45; defaultRotation += 15)
  253. {
  254. RotationList.Add(defaultRotation.ToString());
  255. }
  256. }
  257. private void InitOpacityList()
  258. {
  259. OpacityList.Clear();
  260. for (int defaultOpacity = 10; defaultOpacity <= 100; defaultOpacity += 10)
  261. {
  262. OpacityList.Add(defaultOpacity.ToString() + " %");
  263. }
  264. }
  265. private void InitRelativeRatioList()
  266. {
  267. RelativeRatioList.Clear();
  268. for (int defaultRelativeRatioList = 10; defaultRelativeRatioList <= 100; defaultRelativeRatioList += 10)
  269. {
  270. RelativeRatioList.Add(defaultRelativeRatioList.ToString() + " %");
  271. }
  272. }
  273. private void InitLocationButtonMatrix()
  274. {
  275. GetLocationFromNumber.Clear();
  276. for (var temp = 0; temp <= 22; temp++)
  277. {
  278. GetLocationFromNumber.Add(temp.ToString(), true);
  279. if (temp % 10 == 2)
  280. {
  281. temp += 7;
  282. }
  283. }
  284. int Num = (int)BackgroundInfo.Vertalign * 10 + (int)BackgroundInfo.Horizalign;
  285. GetLocationFromNumber[Num.ToString()] = false;
  286. }
  287. public void InitComponentBySelectedInfo()
  288. {
  289. ConvertItemToInfo(TemplateBackgroundItem, ref BackgroundInfo);
  290. RotationText = BackgroundInfo.Rotation.ToString();
  291. OpacityText = BackgroundInfo.Opacity.ToString();
  292. InitLocationButtonMatrix();
  293. IsRelativeScaleValue = BackgroundInfo.IsRelativeScale;
  294. RelativeScaleText = BackgroundInfo.Scale.ToString();
  295. HorizontalOffsetValue = (BackgroundInfo.HorizOffset).ToString();
  296. VerticalOffsetValue = (BackgroundInfo.VertOffset).ToString();
  297. PageRangeSelectIndex = BackgroundInfo.PageRangeIndex;
  298. }
  299. public void ChangeLocation(object e)
  300. {
  301. string args = e as string;
  302. if (args != null)
  303. {
  304. BackgroundInfo.Vertalign = (C_Background_Vertalign)(int.Parse(args) / 10);
  305. BackgroundInfo.Horizalign = (C_Background_Horizalign)(int.Parse(args) % 10);
  306. eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
  307. {
  308. Unicode = Unicode,
  309. Status = BackgroundInfo
  310. });
  311. InitLocationButtonMatrix();
  312. }
  313. }
  314. public void OpenFile()
  315. {
  316. System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
  317. dlg.Multiselect = false;
  318. dlg.Filter = "PDF|*.png;*.jpg;*.pdf";
  319. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  320. {
  321. FileNameText = dlg.SafeFileName;
  322. FileInfo file = new FileInfo(dlg.FileName);
  323. if (file.Extension == ".pdf")
  324. {
  325. GetBitmapFromDocment(dlg.FileName);
  326. }
  327. else
  328. {
  329. EditToolsHelper.ChooseFile(dlg.FileName, ref BackgroundInfo);
  330. }
  331. CreateModFileVisible = Visibility.Visible;
  332. eventAggregator.GetEvent<SetBackgroundEvent>().Publish(new BackgroundInfoUnicode
  333. {
  334. Unicode = Unicode,
  335. Status = BackgroundInfo
  336. });
  337. }
  338. }
  339. public async void GetBitmapFromDocment(string filePath)
  340. {
  341. CPDFDocument document = CPDFDocument.InitWithFilePath(filePath);
  342. CPDFPage page = document.PageAtIndex(0);
  343. byte[] bmp_data = new byte[(int)page.PageSize.Width * (int)page.PageSize.Height * 4];
  344. await Task.Run(delegate
  345. {
  346. page.RenderPageBitmap(0, 0, (int)page.PageSize.Width, (int)page.PageSize.Height, 0xffffffff, bmp_data, 1);
  347. });
  348. BackgroundInfo.ImageArray = bmp_data;
  349. BackgroundInfo.ImageWidth = (int)page.PageSize.Width;
  350. BackgroundInfo.ImageHeight = (int)page.PageSize.Height;
  351. document.ReleasePages();
  352. document.Release();
  353. }
  354. public void ConvertItemToInfo(BackgroundItem backgroundItem, ref BackgroundInfo backgroundInfo)
  355. {
  356. if (backgroundItem != null)
  357. {
  358. backgroundInfo.BackgroundType = C_Background_Type.BG_TYPE_IMAGE;
  359. backgroundInfo.Color = backgroundItem.bgColor;
  360. backgroundInfo.Horizalign = backgroundItem.horizalign;
  361. backgroundInfo.Vertalign = backgroundItem.vertalign;
  362. backgroundInfo.VertOffset = backgroundItem.vertOffset;
  363. backgroundInfo.Horizalign = backgroundItem.horizalign;
  364. backgroundInfo.Opacity = backgroundItem.opacity;
  365. backgroundInfo.Rotation = backgroundItem.rotation;
  366. backgroundInfo.IsRelativeScale = backgroundItem.isRelativeScale;
  367. backgroundInfo.Scale = backgroundItem.scale;
  368. backgroundInfo.PageRangeIndex = backgroundItem.PageRangeIndex;
  369. backgroundInfo.PageRange = backgroundItem.pageRange;
  370. }
  371. }
  372. public void ConvertInfoToItem(ref BackgroundItem backgroundItem, BackgroundInfo backgroundInfo)
  373. {
  374. backgroundItem.type = C_Background_Type.BG_TYPE_IMAGE;
  375. backgroundItem.imageArray = backgroundInfo.ImageArray;
  376. backgroundItem.imageWidth = backgroundInfo.ImageWidth;
  377. backgroundItem.imageHeight = backgroundInfo.ImageHeight;
  378. backgroundItem.horizalign = backgroundInfo.Horizalign;
  379. backgroundItem.vertalign = backgroundInfo.Vertalign;
  380. backgroundItem.vertOffset = backgroundInfo.VertOffset;
  381. backgroundItem.horizalign = backgroundInfo.Horizalign;
  382. backgroundItem.opacity = backgroundInfo.Opacity;
  383. backgroundItem.rotation = backgroundInfo.Rotation;
  384. backgroundItem.isRelativeScale = backgroundInfo.IsRelativeScale;
  385. backgroundItem.scale = backgroundInfo.Scale;
  386. //backgroundItem.pagRangeMode = backgroundInfo.PageRange;
  387. }
  388. public void SaveCurrentTemplate()
  389. {
  390. var backgroundItem = new BackgroundItem();
  391. ConvertInfoToItem(ref backgroundItem, BackgroundInfo);
  392. backgroundItem.templateName += Settings.Default.BackgroundIndex.ToString();
  393. try
  394. {
  395. //创建缓存文件夹
  396. string folderPath = Path.Combine(App.CurrentPath, "Background");
  397. //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除同名文件
  398. //保险措施(猜测)
  399. if (File.Exists(folderPath))
  400. {
  401. File.Delete(folderPath);
  402. }
  403. DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
  404. if (!tempfolder.Exists)
  405. {
  406. tempfolder.Create();
  407. }
  408. //预览图缓存
  409. string saveName = Guid.NewGuid().ToString();
  410. string savePath = Path.Combine(folderPath, saveName);
  411. System.Windows.Size pageSize = PDFViewer.Document.GetPageSize(0);
  412. CPDFDocument tempDocument = CPDFDocument.CreateDocument();
  413. if (tempDocument != null)
  414. {
  415. tempDocument.InsertPage(0, pageSize.Width, pageSize.Height, null);
  416. var tempBackground = tempDocument.GetBackground();
  417. tempBackground.SetBackgroundType(BackgroundInfo.BackgroundType);
  418. tempBackground.SetImage(BackgroundInfo.ImageArray, BackgroundInfo.ImageWidth, BackgroundInfo.ImageHeight, ComPDFKit.Import.C_Scale_Type.fitCenter);
  419. if (!BackgroundInfo.IsRelativeScale)
  420. {
  421. tempBackground.SetScale(1);
  422. }
  423. else
  424. {
  425. tempBackground.SetScale(BackgroundInfo.Scale/100);
  426. }
  427. tempBackground.SetRotation((float)((BackgroundInfo.Rotation / 180) * Math.PI));
  428. tempBackground.SetOpacity((byte)((float)(BackgroundInfo.Opacity / 100) * 255));
  429. tempBackground.SetVertalign(BackgroundInfo.Vertalign);
  430. tempBackground.SetHorizalign(BackgroundInfo.Horizalign);
  431. tempBackground.SetXOffset(BackgroundInfo.HorizOffset);
  432. tempBackground.SetYOffset(BackgroundInfo.VertOffset);
  433. tempBackground.SetPages("0");
  434. tempBackground.SetAllowsPrint(true);
  435. tempBackground.SetAllowsView(true);
  436. tempBackground.Update();
  437. //获取透明背景的图片
  438. var bitmap = ToolMethod.RenderPageBitmapNoWait(tempDocument, (int)pageSize.Width, (int)pageSize.Height, 0, false, false, 0x00FFFFFF);
  439. using (FileStream stream = new FileStream(savePath, FileMode.Create))
  440. {
  441. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  442. }
  443. backgroundItem.previewImagePath = savePath;
  444. tempDocument.Release();
  445. Settings.Default.BackgroundTemplateList.Add(backgroundItem);
  446. Settings.Default.Save();
  447. }
  448. }
  449. catch
  450. {
  451. }
  452. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
  453. {
  454. Unicode = Unicode,
  455. Status = EnumTemplateListOrCreate.StatusTemplate
  456. });
  457. }
  458. public void ConfirmEditBackgroundTemplateItem(EnumColorOrFileUnicode enumColorOrFileunicode)
  459. {
  460. EnumColorOrFile enumColorOrFile = enumColorOrFileunicode.Status;
  461. if (enumColorOrFile == EnumColorOrFile.StatusFile)
  462. {
  463. var backgroundItem = new BackgroundItem();
  464. ConvertInfoToItem(ref backgroundItem, BackgroundInfo);
  465. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode { Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusTemplate });
  466. try
  467. {
  468. //创建缓存文件夹
  469. string folderPath = Path.Combine(App.CurrentPath, "Background");
  470. //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除同名文件
  471. //保险措施(猜测)
  472. if (File.Exists(folderPath))
  473. {
  474. File.Delete(folderPath);
  475. }
  476. DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
  477. if (!tempfolder.Exists)
  478. {
  479. tempfolder.Create();
  480. }
  481. //预览图缓存
  482. string saveName = Guid.NewGuid().ToString();
  483. string savePath = Path.Combine(folderPath, saveName);
  484. System.Windows.Size pageSize = PDFViewer.Document.GetPageSize(0);
  485. CPDFDocument tempDocument = CPDFDocument.CreateDocument();
  486. if (tempDocument != null)
  487. {
  488. tempDocument.InsertPage(0, pageSize.Width, pageSize.Height, null);
  489. var tempBackground = tempDocument.GetBackground();
  490. tempBackground.SetBackgroundType(BackgroundInfo.BackgroundType);
  491. tempBackground.SetImage(BackgroundInfo.ImageArray, BackgroundInfo.ImageWidth, BackgroundInfo.ImageHeight, ComPDFKit.Import.C_Scale_Type.fitCenter);
  492. if (!BackgroundInfo.IsRelativeScale)
  493. {
  494. tempBackground.SetScale(1);
  495. }
  496. else
  497. {
  498. tempBackground.SetScale(BackgroundInfo.Scale/100);
  499. }
  500. tempBackground.SetRotation((float)((BackgroundInfo.Rotation / 180) * Math.PI));
  501. tempBackground.SetOpacity((byte)((float)(BackgroundInfo.Opacity / 100) * 255));
  502. tempBackground.SetVertalign(BackgroundInfo.Vertalign);
  503. tempBackground.SetHorizalign(BackgroundInfo.Horizalign);
  504. tempBackground.SetXOffset(BackgroundInfo.HorizOffset);
  505. tempBackground.SetYOffset(BackgroundInfo.VertOffset);
  506. tempBackground.SetPages("0");
  507. tempBackground.SetAllowsPrint(true);
  508. tempBackground.SetAllowsView(true);
  509. tempBackground.Update();
  510. //获取透明背景的图片
  511. var bitmap = ToolMethod.RenderPageBitmapNoWait(tempDocument, (int)pageSize.Width, (int)pageSize.Height, 0, false, false, 0x00FFFFFF);
  512. using (FileStream stream = new FileStream(savePath, FileMode.Create))
  513. {
  514. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  515. }
  516. backgroundItem.previewImagePath = savePath;
  517. tempDocument.Release();
  518. Settings.Default.BackgroundTemplateList[TemplateBackgroundItem.listIndex] = backgroundItem;
  519. Settings.Default.Save();
  520. }
  521. }
  522. catch
  523. {
  524. }
  525. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
  526. {
  527. Unicode = Unicode,
  528. Status = EnumTemplateListOrCreate.StatusTemplate
  529. });
  530. }
  531. }
  532. public void SaveBackgroundTemplate(EnumColorOrFileUnicode enumColorOrFileunicode)
  533. {
  534. EnumColorOrFile enumColorOrFile = enumColorOrFileunicode.Status;
  535. if (enumColorOrFile == EnumColorOrFile.StatusFile)
  536. {
  537. SaveCurrentTemplate();
  538. }
  539. }
  540. public bool IsNavigationTarget(NavigationContext navigationContext)
  541. {
  542. return true;
  543. }
  544. public void OnNavigatedFrom(NavigationContext navigationContext)
  545. {
  546. }
  547. public void OnNavigatedTo(NavigationContext navigationContext)
  548. {
  549. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  550. navigationContext.Parameters.TryGetValue<string>("UniCode", out unicode);
  551. if (navigationContext.Parameters.TryGetValue<BackgroundItem>("BackgroundItem", out TemplateBackgroundItem))
  552. {
  553. InitComponentBySelectedInfo();
  554. }
  555. }
  556. }
  557. }