CreateFromHtmlDialogViewModel.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using Microsoft.Win32;
  2. using PDF_Office.Model;
  3. using PDF_Office.Model.Dialog.HomePageToolsDialogs;
  4. using Prism.Commands;
  5. using Prism.Mvvm;
  6. using Prism.Services.Dialogs;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
  13. {
  14. public class CreateFromHtmlDialogViewModel : BindableBase, IDialogAware
  15. {
  16. public string Title => "";
  17. public event Action<IDialogResult> RequestClose;
  18. private string filepath = "";
  19. public string FilePath
  20. {
  21. get { return filepath; }
  22. set
  23. {
  24. SetProperty(ref filepath, value);
  25. if(!string.IsNullOrEmpty(value))
  26. {
  27. Model.FilePath = value;
  28. }
  29. }
  30. }
  31. private double margin = 0;
  32. public double Margin
  33. {
  34. get { return margin; }
  35. set
  36. {
  37. SetProperty(ref margin, value);
  38. Model.Margin = value;
  39. }
  40. }
  41. private int selectedIndex = 0;
  42. public int SelectedIndex
  43. {
  44. get { return selectedIndex; }
  45. set
  46. {
  47. SetProperty(ref selectedIndex, value);
  48. }
  49. }
  50. public List<string> PageSizes { get; set; }
  51. /// <summary>
  52. /// 数据模型
  53. /// </summary>
  54. public HtmlModel Model { get; set; } = new HtmlModel();
  55. public DelegateCommand OpenFileCommnad { get; set; }
  56. public DelegateCommand CreateCommand { get; set; }
  57. public DelegateCommand CancelCommand { get; set; }
  58. public CreateFromHtmlDialogViewModel()
  59. {
  60. OpenFileCommnad = new DelegateCommand(openFile);
  61. CreateCommand = new DelegateCommand(createFile);
  62. CancelCommand = new DelegateCommand(cancel);
  63. }
  64. private void createFile()
  65. {
  66. DialogParameters valuePairs = new DialogParameters();
  67. valuePairs.Add(ParameterNames.DataModel, Model);
  68. RequestClose.Invoke(new DialogResult(ButtonResult.OK,valuePairs));
  69. }
  70. private void cancel()
  71. {
  72. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  73. }
  74. private void openFile()
  75. {
  76. OpenFileDialog dialog = new OpenFileDialog();
  77. dialog.Multiselect = false;
  78. dialog.Filter = "HTML(*.html)|*.html";
  79. if((bool)dialog.ShowDialog())
  80. {
  81. if(!string.IsNullOrEmpty(dialog.FileName))
  82. {
  83. FilePath = dialog.FileName;
  84. }
  85. }
  86. }
  87. #region 框架
  88. public bool CanCloseDialog()
  89. {
  90. return true;
  91. }
  92. public void OnDialogClosed()
  93. {
  94. }
  95. public void OnDialogOpened(IDialogParameters parameters)
  96. {
  97. }
  98. #endregion
  99. }
  100. }