MainPage.xaml.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using LogoForceTestApp.Modules.MainModule.Models;
  2. using Prism.Events;
  3. using System;
  4. using System.Windows.Controls;
  5. using System.Windows.Forms;
  6. using System.Windows.Input;
  7. using System.Windows.Threading;
  8. namespace LogoForceTestApp.Modules.MainModule.Views
  9. {
  10. /// <summary>
  11. /// MainPage.xaml 的交互逻辑
  12. /// </summary>
  13. public partial class MainPage : System.Windows.Controls.UserControl
  14. {
  15. private readonly IEventAggregator _eventAggregator;
  16. public MainPage(IEventAggregator eventAggregator)
  17. {
  18. _eventAggregator = eventAggregator;
  19. _eventAggregator.GetEvent<LogEvent>().Subscribe(WriteLog);
  20. InitializeComponent();
  21. }
  22. private void WriteLog(Tuple<LogType, string> log)
  23. {
  24. ListBoxMessage?.Dispatcher?.BeginInvoke(DispatcherPriority.Render, new Action(() =>
  25. {
  26. if (ListBoxMessage.Items.Count > 100)
  27. {
  28. ListBoxMessage.Items.RemoveAt(0);
  29. }
  30. var (type, info) = log;
  31. var listBoxItem = new ListBoxItem
  32. {
  33. Content = info
  34. };
  35. if (log.Item1 == LogType.Error)
  36. listBoxItem.Foreground = System.Windows.Media.Brushes.Red;
  37. else if (log.Item1 == LogType.Warning)
  38. listBoxItem.Foreground = System.Windows.Media.Brushes.Yellow;
  39. else
  40. listBoxItem.Foreground = System.Windows.Media.Brushes.DarkOliveGreen;
  41. ListBoxMessage.Items.Add(listBoxItem);
  42. ListBoxMessage.ScrollIntoView(listBoxItem);
  43. }));
  44. }
  45. private void TextBox1_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  46. {
  47. //if(e.Key == Key.Enter)
  48. //{
  49. // TextBox2?.Focus();
  50. //}
  51. }
  52. //private void TextBox2_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  53. //{
  54. // if (e.Key == Key.Enter)
  55. // {
  56. // TextBox3?.Focus();
  57. // }
  58. //}
  59. //private void TextBox3_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  60. //{
  61. // if (e.Key == Key.Enter)
  62. // {
  63. // TextBox4?.Focus();
  64. // }
  65. //}
  66. //private void TextBox4_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  67. //{
  68. // if (e.Key == Key.Enter)
  69. // {
  70. // TextBox5?.Focus();
  71. // }
  72. //}
  73. //private void TextBox5_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  74. //{
  75. // if (e.Key == Key.Enter)
  76. // {
  77. // TextBox6?.Focus();
  78. // }
  79. //}
  80. //private void TextBox6_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  81. //{
  82. // if (e.Key == Key.Enter)
  83. // {
  84. // TextBox7?.Focus();
  85. // }
  86. //}
  87. //private void TextBox7_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  88. //{
  89. // if (e.Key == Key.Enter)
  90. // {
  91. // TextBox8?.Focus();
  92. // }
  93. //}
  94. //private void TextBox8_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  95. //{
  96. // if (e.Key == Key.Enter)
  97. // {
  98. // TextBox9?.Focus();
  99. // }
  100. //}
  101. //private void TextBox9_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  102. //{
  103. // if (e.Key == Key.Enter)
  104. // {
  105. // TextBox10?.Focus();
  106. // }
  107. //}
  108. }
  109. }