UdpLogListBox.xaml.cs 1.2 KB

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