AlertsMessage.xaml.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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_Office.CustomControl
  15. {
  16. public enum ContentResult
  17. {
  18. Cancel,
  19. MiddleCancel,
  20. Ok
  21. }
  22. /// <summary>
  23. /// AlertsMessage.xaml 的交互逻辑
  24. /// 因为是纯UI的逻辑显示,所以没有再创建VM
  25. /// </summary>
  26. public partial class AlertsMessage : Window
  27. {
  28. public ContentResult result = ContentResult.Cancel;
  29. private Window ownerWindow;
  30. public AlertsMessage()
  31. {
  32. InitializeComponent();
  33. ownerWindow = App.Current.MainWindow;
  34. }
  35. /// <summary>
  36. /// 一个按钮弹窗
  37. /// </summary>
  38. public void Show(string title, string content,string okBtn)
  39. {
  40. TitleText.Text = title;
  41. ContentText.Text = content;
  42. CancelBtn.Visibility = Visibility.Collapsed;
  43. MiddleCancelBtn.Visibility = Visibility.Collapsed;
  44. OkBtn.Content = okBtn;
  45. Width = 408;
  46. Grid.SetColumn(OkBtn, 3);
  47. BtnGrid.ColumnDefinitions.Clear();
  48. var column = new ColumnDefinition();
  49. var column2 = new ColumnDefinition();
  50. var column3 = new ColumnDefinition();
  51. column.Width = new GridLength(1, GridUnitType.Star);
  52. column2.Width = new GridLength(1, GridUnitType.Star);
  53. column3.Width = new GridLength(1, GridUnitType.Star);
  54. BtnGrid.ColumnDefinitions.Add(column);
  55. BtnGrid.ColumnDefinitions.Add(column2);
  56. BtnGrid.ColumnDefinitions.Add(column3);
  57. this.Show();
  58. }
  59. /// <summary>
  60. /// 两个按钮弹窗
  61. /// </summary>
  62. public void Show(string title,string content,string cancelBtn,string okBtn)
  63. {
  64. TitleText.Text = title;
  65. ContentText.Text = content;
  66. CancelBtn.Visibility = Visibility.Collapsed;
  67. MiddleCancelBtn.Content = cancelBtn;
  68. OkBtn.Content = okBtn;
  69. Width = 408;
  70. Grid.SetColumn(MiddleCancelBtn, 0);
  71. Grid.SetColumn(OkBtn, 1);
  72. BtnGrid.ColumnDefinitions.Clear();
  73. var column = new ColumnDefinition();
  74. var column2 = new ColumnDefinition();
  75. column.Width = new GridLength(1, GridUnitType.Star);
  76. column2.Width = new GridLength(1, GridUnitType.Star);
  77. BtnGrid.ColumnDefinitions.Add(column);
  78. BtnGrid.ColumnDefinitions.Add(column2);
  79. this.Show();
  80. }
  81. /// <summary>
  82. /// 三个按钮弹窗
  83. /// </summary>
  84. public void Show(string title, string content, string cancelBtn1, string cancelBtn2, string okBtn)
  85. {
  86. TitleText.Text = title;
  87. ContentText.Text = content;
  88. CancelBtn.Visibility = Visibility.Visible;
  89. CancelBtn.Content = cancelBtn1;
  90. MiddleCancelBtn.Content = cancelBtn2;
  91. OkBtn.Content = okBtn;
  92. Grid.SetColumn(CancelBtn, 0);
  93. Grid.SetColumn(MiddleCancelBtn, 1);
  94. Grid.SetColumn(OkBtn, 2);
  95. BtnGrid.ColumnDefinitions.Clear();
  96. var column = new ColumnDefinition();
  97. var column2 = new ColumnDefinition();
  98. var column3 = new ColumnDefinition();
  99. column.Width = new GridLength(1, GridUnitType.Star);
  100. column2.Width = new GridLength(1, GridUnitType.Star);
  101. column3.Width = new GridLength(1, GridUnitType.Star);
  102. BtnGrid.ColumnDefinitions.Add(column);
  103. BtnGrid.ColumnDefinitions.Add(column2);
  104. BtnGrid.ColumnDefinitions.Add(column3);
  105. this.Show();
  106. }
  107. public void ShowDialog(string title, string content, string okBtn)
  108. {
  109. TitleText.Text = title;
  110. ContentText.Text = content;
  111. CancelBtn.Visibility = Visibility.Collapsed;
  112. MiddleCancelBtn.Visibility = Visibility.Collapsed;
  113. OkBtn.Content = okBtn;
  114. Width = 408;
  115. Grid.SetColumn(OkBtn, 3);
  116. BtnGrid.ColumnDefinitions.Clear();
  117. var column = new ColumnDefinition();
  118. var column2 = new ColumnDefinition();
  119. var column3 = new ColumnDefinition();
  120. column.Width = new GridLength(1, GridUnitType.Star);
  121. column2.Width = new GridLength(1, GridUnitType.Star);
  122. column3.Width = new GridLength(1, GridUnitType.Star);
  123. BtnGrid.ColumnDefinitions.Add(column);
  124. BtnGrid.ColumnDefinitions.Add(column2);
  125. BtnGrid.ColumnDefinitions.Add(column3);
  126. if (ownerWindow != null)
  127. {
  128. Owner = ownerWindow;
  129. WindowStartupLocation = WindowStartupLocation.CenterOwner;
  130. ShowDialog();
  131. }
  132. }
  133. public void ShowDialog(string title, string content, string cancelBtn, string okBtn)
  134. {
  135. TitleText.Text = title;
  136. ContentText.Text = content;
  137. CancelBtn.Visibility = Visibility.Collapsed;
  138. MiddleCancelBtn.Content = cancelBtn;
  139. OkBtn.Content = okBtn;
  140. Width = 408;
  141. Grid.SetColumn(MiddleCancelBtn, 0);
  142. Grid.SetColumn(OkBtn, 1);
  143. BtnGrid.ColumnDefinitions.Clear();
  144. var column = new ColumnDefinition();
  145. var column2 = new ColumnDefinition();
  146. column.Width = new GridLength(1, GridUnitType.Star);
  147. column2.Width = new GridLength(1, GridUnitType.Star);
  148. BtnGrid.ColumnDefinitions.Add(column);
  149. BtnGrid.ColumnDefinitions.Add(column2);
  150. if (ownerWindow != null)
  151. {
  152. Owner = ownerWindow;
  153. WindowStartupLocation = WindowStartupLocation.CenterOwner;
  154. ShowDialog();
  155. }
  156. }
  157. public void ShowDialog(string title, string content, string cancelBtn1, string cancelBtn2, string okBtn)
  158. {
  159. TitleText.Text = title;
  160. ContentText.Text = content;
  161. CancelBtn.Visibility = Visibility.Visible;
  162. CancelBtn.Content = cancelBtn1;
  163. MiddleCancelBtn.Content = cancelBtn2;
  164. OkBtn.Content = okBtn;
  165. Grid.SetColumn(CancelBtn, 0);
  166. Grid.SetColumn(MiddleCancelBtn, 1);
  167. Grid.SetColumn(OkBtn, 2);
  168. BtnGrid.ColumnDefinitions.Clear();
  169. var column = new ColumnDefinition();
  170. var column2 = new ColumnDefinition();
  171. var column3 = new ColumnDefinition();
  172. column.Width = new GridLength(1, GridUnitType.Star);
  173. column2.Width = new GridLength(1, GridUnitType.Star);
  174. column3.Width = new GridLength(1, GridUnitType.Star);
  175. BtnGrid.ColumnDefinitions.Add(column);
  176. BtnGrid.ColumnDefinitions.Add(column2);
  177. BtnGrid.ColumnDefinitions.Add(column3);
  178. if (ownerWindow != null)
  179. {
  180. Owner = ownerWindow;
  181. WindowStartupLocation = WindowStartupLocation.CenterOwner;
  182. ShowDialog();
  183. }
  184. }
  185. private void CancelBtn_Click(object sender, RoutedEventArgs e)
  186. {
  187. result = ContentResult.Cancel;
  188. Close();
  189. }
  190. private void MiddleCancelBtn_Click(object sender, RoutedEventArgs e)
  191. {
  192. result = ContentResult.MiddleCancel;
  193. Close();
  194. }
  195. private void OkBtn_Click(object sender, RoutedEventArgs e)
  196. {
  197. result = ContentResult.Ok;
  198. Close();
  199. }
  200. private void Border_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  201. {
  202. this.DragMove();
  203. }
  204. }
  205. }