HomePagePrinterModSizeContentViewModel.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using PDF_Office.EventAggregators;
  2. using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePagePrinter;
  3. using Prism.Commands;
  4. using Prism.Events;
  5. using Prism.Mvvm;
  6. using Prism.Regions;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Management.Instrumentation;
  11. using System.Windows.Controls;
  12. namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
  13. {
  14. public class HomePagePrinterModSizeContentViewModel : BindableBase, INavigationAware
  15. {
  16. private IEventAggregator eventAggregator;
  17. private string Unicode = null;
  18. public string CurrentSelectedRdoName = "StatusAdaptiveRdo";
  19. private string _displayRatio = "100";
  20. public string DisplayRatio
  21. {
  22. get { return _displayRatio; }
  23. set { SetProperty(ref _displayRatio, value); }
  24. }
  25. private SizeInfo _sizeInfo;
  26. public SizeInfo SizeInfo
  27. {
  28. get { return _sizeInfo; }
  29. set { _sizeInfo = value; }
  30. }
  31. public DelegateCommand<object> SetModSizeStatusCommand { get; set; }
  32. public DelegateCommand SetDisplayRatioCommand { get; set; }
  33. //public DelegateCommand sendSizeInfoCommand;
  34. //public DelegateCommand SendSizeInfoCommand => this.SendSizeInfoCommand ?? (this.sendSizeInfoCommand = new DelegateCommand(() => this.eventAggregator.GetEvent<ModInfoSendEvent>().Publish(PrintMod)));
  35. public DelegateCommand SendSizeInfoCommand { get; set; }
  36. public HomePagePrinterModSizeContentViewModel(IEventAggregator eventAggregator)
  37. {
  38. this.eventAggregator = eventAggregator;
  39. SizeInfo = new SizeInfo();
  40. SizeInfo.EnumPrintMod = EnumPrintMod.StatusSize;
  41. SetModSizeStatusCommand = new DelegateCommand<object>(SetModSizeStatus);
  42. SetDisplayRatioCommand = new DelegateCommand(SetDisplayRatio);
  43. }
  44. public void SendSizeInfo()
  45. {
  46. if (SizeInfo != null)
  47. {
  48. this.eventAggregator.GetEvent<SendPrintSettingsModInfoEvent>().Publish(new PrintModInfoWithUnicode { printModInfo = SizeInfo, Unicode = this.Unicode});
  49. }
  50. }
  51. public void SetModSizeStatus(object e)
  52. {
  53. var rdo = e as RadioButton;
  54. if (rdo.Name == CurrentSelectedRdoName)
  55. {
  56. return;
  57. }
  58. else
  59. {
  60. CurrentSelectedRdoName = rdo.Name;
  61. if (rdo.Name == "StatusAdaptiveRdo")
  62. {
  63. SizeInfo.EnumSizeType = EnumSizeType.StatusAdaptive;
  64. }
  65. else if (rdo.Name == "StatusActuralRdo")
  66. {
  67. SizeInfo.EnumSizeType = EnumSizeType.StatusActural;
  68. }
  69. else
  70. {
  71. SizeInfo.EnumSizeType = EnumSizeType.StatusCustomized;
  72. }
  73. if (SizeInfo.EnumSizeType == EnumSizeType.StatusAdaptive || SizeInfo.EnumSizeType == EnumSizeType.StatusActural || (SizeInfo.EnumSizeType == EnumSizeType.StatusCustomized)&& DisplayRatio != null)
  74. {
  75. SendSizeInfo();
  76. }
  77. }
  78. }
  79. public void SetDisplayRatio()
  80. {
  81. int previousDisplayRatio = SizeInfo.DisplayRatio;
  82. SizeInfo.DisplayRatio = int.Parse(DisplayRatio);
  83. if (previousDisplayRatio != SizeInfo.DisplayRatio)
  84. {
  85. SendSizeInfo();
  86. }
  87. }
  88. public bool IsNavigationTarget(NavigationContext navigationContext)
  89. {
  90. return true;
  91. }
  92. public void OnNavigatedFrom(NavigationContext navigationContext)
  93. {
  94. }
  95. public void OnNavigatedTo(NavigationContext navigationContext)
  96. {
  97. navigationContext.Parameters.TryGetValue<string>("Unicode", out Unicode);
  98. SendSizeInfo();
  99. }
  100. }
  101. }