using Microsoft.Win32; using PDF_Office.Model; using PDF_Office.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_Office.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); } } public List PageSizes { get; set; } /// /// 数据模型 /// 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); CancelCommand = new DelegateCommand(cancel); } private void createFile() { DialogParameters valuePairs = new DialogParameters(); valuePairs.Add(ParameterNames.DataModel, Model); RequestClose.Invoke(new DialogResult(ButtonResult.OK,valuePairs)); } 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 } }