NoviceGuidDialogViewModel.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. using PDF_Master.Model;
  2. using PDF_Master.Model.Dialog;
  3. using Prism.Commands;
  4. using Prism.Mvvm;
  5. using Prism.Services.Dialogs;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. namespace PDF_Master.ViewModels.Dialog
  14. {
  15. public class NoviceGuidDialogViewModel :BindableBase,IDialogAware
  16. {
  17. public string Title => "";
  18. public event Action<IDialogResult> RequestClose;
  19. private int selectedIndex;
  20. /// <summary>
  21. /// 免费试用天数
  22. /// </summary>
  23. private string trialDays = "7";
  24. /// <summary>
  25. /// 选中索引
  26. /// </summary>
  27. public int SelectedIndex
  28. {
  29. get { return selectedIndex; }
  30. set
  31. {
  32. SetProperty(ref selectedIndex, value);
  33. if(SelectedIndex==ItemSource.Count-1)
  34. {
  35. SignUpVisible = Visibility.Visible;
  36. }
  37. else
  38. {
  39. SignUpVisible = Visibility.Collapsed;
  40. }
  41. if(SelectedIndex==0)
  42. {
  43. NextTimeVisible = Visibility.Visible;
  44. }
  45. else
  46. {
  47. NextTimeVisible = Visibility.Hidden;
  48. }
  49. }
  50. }
  51. private Visibility signUpVisible = Visibility.Collapsed;
  52. /// <summary>
  53. /// 是否显示SignUp按钮
  54. /// </summary>
  55. public Visibility SignUpVisible
  56. {
  57. get { return signUpVisible; }
  58. set
  59. {
  60. SetProperty(ref signUpVisible, value);
  61. }
  62. }
  63. private Visibility nexttimeVisible;
  64. public Visibility NextTimeVisible
  65. {
  66. get { return nexttimeVisible; }
  67. set
  68. {
  69. SetProperty(ref nexttimeVisible, value);
  70. }
  71. }
  72. private string T_btnNextStep;
  73. public string T_BtnNextStep
  74. {
  75. get { return T_btnNextStep; }
  76. set
  77. {
  78. SetProperty(ref T_btnNextStep, value);
  79. }
  80. }
  81. private string T_btnNextTime;
  82. public string T_BtnNextTime
  83. {
  84. get { return T_btnNextTime; }
  85. set
  86. {
  87. SetProperty(ref T_btnNextTime, value);
  88. }
  89. }
  90. private string T_btnSignUp;
  91. public string T_BtnSignUp
  92. {
  93. get { return T_btnSignUp; }
  94. set
  95. {
  96. SetProperty(ref T_btnSignUp, value);
  97. }
  98. }
  99. public DelegateCommand NextPageCommand { get; set; }
  100. public DelegateCommand PrePageCommand { get; set; }
  101. public DelegateCommand NextTimeCommand { get; set; }
  102. public DelegateCommand SignUpCommand { get; set; }
  103. public ObservableCollection<GuidItemModel> ItemSource { get; set; }
  104. private IDialogService dialog;
  105. public NoviceGuidDialogViewModel(IDialogService dialogService)
  106. {
  107. dialog = dialogService;
  108. NextPageCommand = new DelegateCommand(NextPage,CanNextPageExcute).ObservesProperty(()=>SelectedIndex);
  109. PrePageCommand = new DelegateCommand(PrePage,CanPrePageExcute).ObservesProperty(()=>SelectedIndex);
  110. SignUpCommand = new DelegateCommand(SignUp);
  111. NextTimeCommand = new DelegateCommand(nexttime);
  112. InitItemSource();
  113. InitString();
  114. }
  115. private void InitString()
  116. {
  117. T_BtnNextStep = App.HomePageLoader.GetString("Guid_AcceptButton");
  118. T_BtnNextTime = App.HomePageLoader.GetString("Guid_LaterButton");
  119. T_BtnSignUp = App.ServiceLoader.GetString("Text_Signup");
  120. }
  121. private void nexttime()
  122. {
  123. //忽略,下次再看
  124. this.RequestClose(new DialogResult(ButtonResult.Ignore));
  125. }
  126. private void InitItemSource()
  127. {
  128. ItemSource = new ObservableCollection<GuidItemModel>();
  129. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/Guid_Office.png", Title = App.HomePageLoader.GetString("GuidTitleP1"), Content = string.Format(App.HomePageLoader.GetString("GuidContentP1"),trialDays) }) ;
  130. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/Guid_Annote.png", Title = App.HomePageLoader.GetString("GuidTitleP2"), Content =App.HomePageLoader.GetString("GuidContentP2") });
  131. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/Guid_Convert.png", Title = App.HomePageLoader.GetString("GuidTitleP3"), Content = App.HomePageLoader.GetString("GuidContentP3") });
  132. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/Guid_FillAndSign.png", Title = App.HomePageLoader.GetString("GuidTitleP4"), Content = App.HomePageLoader.GetString("GuidContentP4") });
  133. ItemSource.Add(new GuidItemModel() { ImageSource = "pack://application:,,,/PDF Master;component/Resources/GuidItems/Guid_SignUp.png", Title = App.HomePageLoader.GetString("GuidTitleP5"), Content = App.HomePageLoader.GetString("GuidContentP5") });
  134. }
  135. /// <summary>
  136. /// 前一页
  137. /// </summary>
  138. private void NextPage()
  139. {
  140. SelectedIndex++;
  141. }
  142. /// <summary>
  143. /// 下一页
  144. /// </summary>
  145. private void PrePage()
  146. {
  147. SelectedIndex--;
  148. }
  149. /// <summary>
  150. /// 注册
  151. /// </summary>
  152. private void SignUp()
  153. {
  154. RequestClose.Invoke(new DialogResult());
  155. dialog.ShowDialog(DialogNames.RegisterDialog);
  156. }
  157. /// <summary>
  158. /// 下一次显示
  159. /// </summary>
  160. private void NextTime()
  161. {
  162. //Todo
  163. }
  164. //是否可以执行下一页
  165. private bool CanNextPageExcute()
  166. {
  167. if(SelectedIndex>=ItemSource.Count-1)
  168. {
  169. return false;
  170. }
  171. return true;
  172. }
  173. /// <summary>
  174. /// 是否可以执行上一页
  175. /// </summary>
  176. /// <returns></returns>
  177. private bool CanPrePageExcute()
  178. {
  179. if (SelectedIndex <= 0)
  180. {
  181. return false;
  182. }
  183. return true;
  184. }
  185. public bool CanCloseDialog()
  186. {
  187. return true;
  188. }
  189. public void OnDialogClosed()
  190. {
  191. }
  192. public void OnDialogOpened(IDialogParameters parameters)
  193. {
  194. }
  195. }
  196. }