UdpLogListBox.xaml.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.Windows.Controls;
  4. namespace FastGithub.UI
  5. {
  6. /// <summary>
  7. /// UdpLogListBox.xaml 的交互逻辑
  8. /// </summary>
  9. public partial class UdpLogListBox : UserControl
  10. {
  11. public ObservableCollection<UdpLog> LogList { get; } = new ObservableCollection<UdpLog>();
  12. public UdpLogListBox()
  13. {
  14. InitializeComponent();
  15. this.DataContext = this;
  16. this.InitUdpLoggerAsync();
  17. }
  18. private async void InitUdpLoggerAsync()
  19. {
  20. while (this.Dispatcher.HasShutdownStarted == false)
  21. {
  22. try
  23. {
  24. var log = await UdpLogger.GetUdpLogAsync();
  25. if (log != null)
  26. {
  27. this.LogList.Add(log);
  28. }
  29. }
  30. catch (Exception)
  31. {
  32. }
  33. }
  34. }
  35. private void MenuItem_Copy_Click(object sender, System.Windows.RoutedEventArgs e)
  36. {
  37. if (this.listBox.SelectedValue is UdpLog udpLog)
  38. {
  39. udpLog.SetToClipboard();
  40. }
  41. }
  42. private void MenuItem_Clear_Click(object sender, System.Windows.RoutedEventArgs e)
  43. {
  44. this.LogList.Clear();
  45. }
  46. }
  47. }