MainPage.xaml.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. using LogoForceTestApp.Modules.MainModule.Models;
  2. using Prism.Events;
  3. using System;
  4. using System.Windows.Controls;
  5. using System.Windows.Input;
  6. using System.Windows.Threading;
  7. namespace LogoForceTestApp.Modules.MainModule.Views
  8. {
  9. /// <summary>
  10. /// MainPage.xaml 的交互逻辑
  11. /// </summary>
  12. public partial class MainPage : UserControl
  13. {
  14. private readonly IEventAggregator _eventAggregator;
  15. public MainPage(IEventAggregator eventAggregator)
  16. {
  17. _eventAggregator = eventAggregator;
  18. _eventAggregator.GetEvent<LogEvent>().Subscribe(WriteLog);
  19. InitializeComponent();
  20. }
  21. private void WriteLog(Tuple<LogType, string> log)
  22. {
  23. ListBoxMessage?.Dispatcher?.BeginInvoke(DispatcherPriority.Render, new Action(() =>
  24. {
  25. if (ListBoxMessage.Items.Count > 100)
  26. {
  27. ListBoxMessage.Items.RemoveAt(0);
  28. }
  29. var (type, info) = log;
  30. var listBoxItem = new ListBoxItem
  31. {
  32. Content = info
  33. };
  34. if (log.Item1 == LogType.Error)
  35. listBoxItem.Foreground = System.Windows.Media.Brushes.Red;
  36. else if (log.Item1 == LogType.Warning)
  37. listBoxItem.Foreground = System.Windows.Media.Brushes.Yellow;
  38. else
  39. listBoxItem.Foreground = System.Windows.Media.Brushes.DarkOliveGreen;
  40. ListBoxMessage.Items.Add(listBoxItem);
  41. ListBoxMessage.ScrollIntoView(listBoxItem);
  42. }));
  43. }
  44. private void TextBox1_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  45. {
  46. if (e.Key == Key.Enter)
  47. {
  48. TextBox2?.Focus();
  49. }
  50. }
  51. private void TextBox2_KeyDown(object sender, KeyEventArgs e)
  52. {
  53. if (e.Key == Key.Enter)
  54. {
  55. TextBox3?.Focus();
  56. }
  57. }
  58. private void TextBox3_KeyDown(object sender, KeyEventArgs e)
  59. {
  60. if (e.Key == Key.Enter)
  61. {
  62. TextBox4?.Focus();
  63. }
  64. }
  65. private void TextBox4_KeyDown(object sender, KeyEventArgs e)
  66. {
  67. if (e.Key == Key.Enter)
  68. {
  69. TextBox5?.Focus();
  70. }
  71. }
  72. private void TextBox5_KeyDown(object sender, KeyEventArgs e)
  73. {
  74. if (e.Key == Key.Enter)
  75. {
  76. TextBox6?.Focus();
  77. }
  78. }
  79. private void TextBox6_KeyDown(object sender, KeyEventArgs e)
  80. {
  81. if (e.Key == Key.Enter)
  82. {
  83. TextBox7?.Focus();
  84. }
  85. }
  86. private void TextBox7_KeyDown(object sender, KeyEventArgs e)
  87. {
  88. if (e.Key == Key.Enter)
  89. {
  90. TextBox8?.Focus();
  91. }
  92. }
  93. private void TextBox8_KeyDown(object sender, KeyEventArgs e)
  94. {
  95. if (e.Key == Key.Enter)
  96. {
  97. TextBox9?.Focus();
  98. }
  99. }
  100. private void TextBox9_KeyDown(object sender, KeyEventArgs e)
  101. {
  102. if (e.Key == Key.Enter)
  103. {
  104. TextBox10?.Focus();
  105. }
  106. }
  107. private void TextBox10_KeyDown(object sender, KeyEventArgs e)
  108. {
  109. if (e.Key == Key.Enter)
  110. {
  111. TextBox11?.Focus();
  112. }
  113. }
  114. private void TextBox11_KeyDown(object sender, KeyEventArgs e)
  115. {
  116. if (e.Key == Key.Enter)
  117. {
  118. TextBox12?.Focus();
  119. }
  120. }
  121. private void TextBox12_KeyDown(object sender, KeyEventArgs e)
  122. {
  123. if (e.Key == Key.Enter)
  124. {
  125. TextBox13?.Focus();
  126. }
  127. }
  128. private void TextBox13_KeyDown(object sender, KeyEventArgs e)
  129. {
  130. if (e.Key == Key.Enter)
  131. {
  132. TextBox14?.Focus();
  133. }
  134. }
  135. private void TextBox14_KeyDown(object sender, KeyEventArgs e)
  136. {
  137. if (e.Key == Key.Enter)
  138. {
  139. TextBox15?.Focus();
  140. }
  141. }
  142. private void TextBox15_KeyDown(object sender, KeyEventArgs e)
  143. {
  144. if (e.Key == Key.Enter)
  145. {
  146. TextBox16?.Focus();
  147. }
  148. }
  149. private void TextBox16_KeyDown(object sender, KeyEventArgs e)
  150. {
  151. if (e.Key == Key.Enter)
  152. {
  153. TextBox17?.Focus();
  154. }
  155. }
  156. private void TextBox17_KeyDown(object sender, KeyEventArgs e)
  157. {
  158. if (e.Key == Key.Enter)
  159. {
  160. TextBox18?.Focus();
  161. }
  162. }
  163. private void TextBox18_KeyDown(object sender, KeyEventArgs e)
  164. {
  165. if (e.Key == Key.Enter)
  166. {
  167. TextBox19?.Focus();
  168. }
  169. }
  170. private void TextBox19_KeyDown(object sender, KeyEventArgs e)
  171. {
  172. if (e.Key == Key.Enter)
  173. {
  174. TextBox20?.Focus();
  175. }
  176. }
  177. private void TextBoxProCode_KeyDown(object sender, KeyEventArgs e)
  178. {
  179. if (e.Key == Key.Enter)
  180. {
  181. TextBox1?.Focus();
  182. }
  183. }
  184. }
  185. }