using Microsoft.Win32; using PDF_Master.Model; using PDF_Master.Model.Dialog.HomePageToolsDialogs; using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs { public class CreateFromHtmlDialogViewModel : BindableBase, IDialogAware { public string Title => ""; public event Action RequestClose; private string filepath = ""; public string FilePath { get { return filepath; } set { SetProperty(ref filepath, value); if(!string.IsNullOrEmpty(value)) { Model.FilePath = value; } } } private double margin = 0; public double Margin { get { return margin; } set { SetProperty(ref margin, value); Model.Margin = value; } } private int selectedIndex = 0; public int SelectedIndex { get { return selectedIndex; } set { SetProperty(ref selectedIndex, value); if (value>0) { Model.PageSize = (Microsoft.Office.Interop.Word.WdPaperSize)value; } } } public List PageSizes { get; set; } = new List(); /// /// 数据模型 /// public HtmlModel Model { get; set; } = new HtmlModel(); public DelegateCommand OpenFileCommnad { get; set; } public DelegateCommand CreateCommand { get; set; } public DelegateCommand CancelCommand { get; set; } public CreateFromHtmlDialogViewModel() { OpenFileCommnad = new DelegateCommand(openFile); CreateCommand = new DelegateCommand(createFile,CanExcuteCreateFile).ObservesProperty(()=> FilePath); CancelCommand = new DelegateCommand(cancel); InitPageSize(); } private void InitPageSize() { PageSizes.Add("10x14"); PageSizes.Add("11x17"); PageSizes.Add("Letter"); PageSizes.Add("LetterSmall"); PageSizes.Add("Legal"); PageSizes.Add("Executive"); PageSizes.Add("A3"); PageSizes.Add("A4"); PageSizes.Add("A4Small"); PageSizes.Add("A5"); PageSizes.Add("B4"); PageSizes.Add("B5"); PageSizes.Add("CSheet"); PageSizes.Add("DSheet"); PageSizes.Add("ESheet"); PageSizes.Add("FanfoldLegalGerman"); PageSizes.Add("FanfoldStdGerman"); PageSizes.Add("FanfoldUS"); PageSizes.Add("Folio"); PageSizes.Add("Ledger"); PageSizes.Add("Note"); PageSizes.Add("Quarto"); PageSizes.Add("Statement"); PageSizes.Add("Tabloid"); PageSizes.Add("Envelope9"); PageSizes.Add("Envelope10"); PageSizes.Add("Envelope11"); PageSizes.Add("Envelope12"); PageSizes.Add("EnvelopeB4"); PageSizes.Add("EnvelopeB5"); PageSizes.Add("EnvelopeB6"); PageSizes.Add("EnvelopeC3"); PageSizes.Add("EnvelopeC4"); PageSizes.Add("EnvelopeC6"); PageSizes.Add("EnvelopeC65"); PageSizes.Add("EnvelopeDL"); PageSizes.Add("EnvelopeItaly"); PageSizes.Add("EnvelopeMonarch"); PageSizes.Add("EnvelopePersonal"); } private void createFile() { DialogParameters valuePairs = new DialogParameters(); valuePairs.Add(ParameterNames.DataModel, Model); RequestClose.Invoke(new DialogResult(ButtonResult.OK,valuePairs)); } /// /// 是否可以创建 /// /// private bool CanExcuteCreateFile() { return !string.IsNullOrEmpty(FilePath); } private void cancel() { RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)); } private void openFile() { OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = false; dialog.Filter = "HTML(*.html)|*.html"; if((bool)dialog.ShowDialog()) { if(!string.IsNullOrEmpty(dialog.FileName)) { FilePath = dialog.FileName; } } } #region 框架 public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public void OnDialogOpened(IDialogParameters parameters) { } #endregion } }