AlertsMessage.xaml.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. namespace PDF_Master.CustomControl
  15. {
  16. public enum ContentResult
  17. {
  18. Cancel,
  19. MiddleCancel,
  20. Ok
  21. }
  22. /// <summary>
  23. /// 图标类型
  24. /// </summary>
  25. public enum IconType
  26. {
  27. Tip,
  28. Ask,
  29. Error,
  30. None
  31. }
  32. /// <summary>
  33. /// AlertsMessage.xaml 的交互逻辑
  34. /// 因为是纯UI的逻辑显示,所以没有再创建VM
  35. /// </summary>
  36. public partial class AlertsMessage : Window
  37. {
  38. public ContentResult result = ContentResult.Cancel;
  39. public bool isChecked = false;
  40. private Window ownerWindow;
  41. public AlertsMessage()
  42. {
  43. InitializeComponent();
  44. if (App.Current.MainWindow != this)
  45. {
  46. ownerWindow = App.Current.MainWindow;
  47. }
  48. }
  49. public void ShowAskAgainCheck()
  50. {
  51. ChbDonotAskAgain.Visibility = Visibility.Visible;
  52. }
  53. /// <summary>
  54. /// 两个按钮弹窗
  55. /// </summary>
  56. public void HaveCheckBoxShow(string title, string content,string contentCheckBox, string cancelBtn, string okBtn)
  57. {
  58. TitleText.Text = title;
  59. ContentText.Text = content;
  60. CancelBtn.Visibility = Visibility.Collapsed;
  61. MiddleCancelBtn.Content = cancelBtn;
  62. OkBtn.Content = okBtn;
  63. ChbDonotAskAgain.Content = contentCheckBox;
  64. ChbDonotAskAgain.Visibility = Visibility.Visible;
  65. if (ownerWindow != null)
  66. {
  67. this.Owner = ownerWindow;
  68. ShowDialog();
  69. }
  70. }
  71. /// <summary>
  72. /// 一个按钮弹窗
  73. /// </summary>
  74. public void Show(string title, string content,string okBtn)
  75. {
  76. TitleText.Text = title;
  77. ContentText.Text = content;
  78. CancelBtn.Visibility = Visibility.Collapsed;
  79. MiddleCancelBtn.Visibility = Visibility.Collapsed;
  80. OkBtn.Content = okBtn;
  81. this.Show();
  82. }
  83. /// <summary>
  84. /// 两个按钮弹窗
  85. /// </summary>
  86. public void Show(string title,string content,string cancelBtn,string okBtn)
  87. {
  88. TitleText.Text = title;
  89. ContentText.Text = content;
  90. CancelBtn.Visibility = Visibility.Collapsed;
  91. MiddleCancelBtn.Content = cancelBtn;
  92. OkBtn.Content = okBtn;
  93. this.Show();
  94. }
  95. /// <summary>
  96. /// 三个按钮弹窗
  97. /// </summary>
  98. public void Show(string title, string content, string cancelBtn1, string cancelBtn2, string okBtn)
  99. {
  100. TitleText.Text = title;
  101. ContentText.Text = content;
  102. CancelBtn.Visibility = Visibility.Visible;
  103. CancelBtn.Content = cancelBtn1;
  104. MiddleCancelBtn.Content = cancelBtn2;
  105. OkBtn.Content = okBtn;
  106. this.Show();
  107. }
  108. public void ShowDialog(string title, string content, string okBtn)
  109. {
  110. TitleText.Text = title;
  111. ContentText.Text = content;
  112. CancelBtn.Visibility = Visibility.Collapsed;
  113. MiddleCancelBtn.Visibility = Visibility.Collapsed;
  114. OkBtn.Content = okBtn;
  115. if (ownerWindow != null)
  116. {
  117. Owner = ownerWindow;
  118. WindowStartupLocation = WindowStartupLocation.CenterOwner;
  119. ShowDialog();
  120. }
  121. }
  122. public void ShowDialog(string title, string content, string cancelBtn, string okBtn,IconType type = IconType.None)
  123. {
  124. TitleText.Text = title;
  125. ContentText.Text = content;
  126. CancelBtn.Visibility = Visibility.Collapsed;
  127. MiddleCancelBtn.Content = cancelBtn;
  128. OkBtn.Content = okBtn;
  129. ShowIcon(type);
  130. if (ownerWindow != null)
  131. {
  132. Owner = ownerWindow;
  133. WindowStartupLocation = WindowStartupLocation.CenterOwner;
  134. ShowDialog();
  135. }
  136. }
  137. public void ShowDialog(string title, string content, string okBtn, IconType type = IconType.None)
  138. {
  139. TitleText.Text = title;
  140. ContentText.Text = content;
  141. CancelBtn.Visibility = Visibility.Collapsed;
  142. MiddleCancelBtn.Visibility = Visibility.Collapsed;
  143. OkBtn.Content = okBtn;
  144. ShowIcon(type);
  145. if (ownerWindow != null)
  146. {
  147. Owner = ownerWindow;
  148. WindowStartupLocation = WindowStartupLocation.CenterOwner;
  149. ShowDialog();
  150. }
  151. }
  152. public void ShowDialog(string title, string content, string cancelBtn1, string cancelBtn2, string okBtn)
  153. {
  154. TitleText.Text = title;
  155. ContentText.Text = content;
  156. CancelBtn.Visibility = Visibility.Visible;
  157. CancelBtn.Content = cancelBtn1;
  158. MiddleCancelBtn.Content = cancelBtn2;
  159. OkBtn.Content = okBtn;
  160. if (ownerWindow != null)
  161. {
  162. Owner = ownerWindow;
  163. WindowStartupLocation = WindowStartupLocation.CenterOwner;
  164. ShowDialog();
  165. }
  166. }
  167. private void ShowIcon(IconType type)
  168. {
  169. //先隐藏所有图标
  170. ImgTips.Visibility = Visibility.Collapsed;
  171. switch (type)
  172. {
  173. case IconType.Tip:
  174. GridIcon.Visibility = Visibility.Visible;
  175. ImgTips.Visibility = Visibility.Visible;
  176. break;
  177. case IconType.Ask:
  178. break;
  179. case IconType.Error:
  180. break;
  181. case IconType.None:
  182. default:
  183. GridIcon.Visibility = Visibility.Collapsed;
  184. break;
  185. }
  186. }
  187. private void CancelBtn_Click(object sender, RoutedEventArgs e)
  188. {
  189. result = ContentResult.Cancel;
  190. Close();
  191. }
  192. private void MiddleCancelBtn_Click(object sender, RoutedEventArgs e)
  193. {
  194. result = ContentResult.MiddleCancel;
  195. Close();
  196. }
  197. private void OkBtn_Click(object sender, RoutedEventArgs e)
  198. {
  199. result = ContentResult.Ok;
  200. Close();
  201. }
  202. private void Border_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  203. {
  204. this.DragMove();
  205. }
  206. private void ChbDonotAskAgain_Checked(object sender, RoutedEventArgs e)
  207. {
  208. if (IsLoaded)
  209. {
  210. isChecked = true;
  211. }
  212. }
  213. private void ChbDonotAskAgain_Unchecked(object sender, RoutedEventArgs e)
  214. {
  215. if (IsLoaded)
  216. {
  217. isChecked = false;
  218. }
  219. }
  220. }
  221. }