BackgroundContentViewModel.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using Dropbox.Api.Sharing;
  2. using PDF_Office.EventAggregators;
  3. using Prism.Commands;
  4. using Prism.Events;
  5. using Prism.Mvvm;
  6. using Prism.Regions;
  7. using System;
  8. using System.Windows;
  9. using System.Linq;
  10. using System.Windows.Controls;
  11. using Visibility = System.Windows.Visibility;
  12. using Dropbox.Api.FileProperties;
  13. namespace PDF_Office.ViewModels.EditTools.Background
  14. {
  15. public class BackgroundContentViewModel : BindableBase,INavigationAware
  16. {
  17. public IEventAggregator eventAggregator;
  18. public IRegionManager backgroundRegion;
  19. public string TemplateListName = "BackgroundTemplateListBaseContent";
  20. public string CreateName = "BackgroundCreateBaseContent";
  21. private string _backgroundSettingsRegionName;
  22. public string BackgroundSettingsRegionName
  23. {
  24. get { return _backgroundSettingsRegionName; }
  25. set { _backgroundSettingsRegionName = value;}
  26. }
  27. private Visibility _backgroundSettingsVisible = Visibility.Collapsed;
  28. public Visibility BackgroundSettingsVisible
  29. {
  30. get { return _backgroundSettingsVisible; }
  31. set { _backgroundSettingsVisible = value; }
  32. }
  33. /// <summary>
  34. /// 退出EditTool
  35. /// </summary>
  36. public DelegateCommand CloseEditToolCommand { get; set; }
  37. public DelegateCommand<string> EnterSelectedContentCommand { get; set; }
  38. public BackgroundContentViewModel( IRegionManager regionManager, IEventAggregator eventAggregator)
  39. {
  40. this.eventAggregator = eventAggregator;
  41. this.backgroundRegion = regionManager;
  42. BackgroundSettingsVisible = Visibility.Visible;
  43. BackgroundSettingsRegionName = Guid.NewGuid().ToString();
  44. CloseEditToolCommand = new DelegateCommand(CloseEditTool);
  45. EnterSelectedContentCommand = new DelegateCommand<string>(EnterSelectedContent);
  46. eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate);
  47. }
  48. public void CloseEditTool()
  49. {
  50. this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish();
  51. }
  52. public void EnterTemplateListOrCreate(EnumTemplateListOrCreate enumTemplateListOrCreate)
  53. {
  54. if(enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
  55. {
  56. EnterSelectedContent(TemplateListName);
  57. }
  58. else
  59. {
  60. EnterSelectedContent(CreateName);
  61. }
  62. }
  63. public void EnterSelectedContent(string SelectedContentName)
  64. {
  65. backgroundRegion.RequestNavigate(BackgroundSettingsRegionName, SelectedContentName);
  66. BackgroundSettingsVisible = Visibility.Visible;
  67. }
  68. public void OnNavigatedTo(NavigationContext navigationContext)
  69. {
  70. EnterSelectedContent(TemplateListName);
  71. }
  72. public bool IsNavigationTarget(NavigationContext navigationContext)
  73. {
  74. return true;
  75. }
  76. public void OnNavigatedFrom(NavigationContext navigationContext)
  77. {
  78. }
  79. }
  80. }