MainWindow.xaml.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using System.Threading.Tasks;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using Flyinsono.Client.Test.Log;
  15. namespace Flyinsono.Client.Test
  16. {
  17. /// <summary>
  18. /// Interaction logic for MainWindow.xaml
  19. /// </summary>
  20. public partial class MainWindow : Window
  21. {
  22. private MainWindowViewModel _mainWindowViewModel;
  23. public MainWindow()
  24. {
  25. var logEngine = new LogEngineImplement((s) =>
  26. {
  27. AddLog(s);
  28. });
  29. Logger.RegisterEngine(logEngine);
  30. AppManager.Instance.Initialize();
  31. _mainWindowViewModel = new MainWindowViewModel(RunOnMainDispatcher);
  32. InitializeComponent();
  33. DataContext = _mainWindowViewModel;
  34. }
  35. private void RunOnMainDispatcher(Action action)
  36. {
  37. App.MainDispatcher.Invoke(action);
  38. }
  39. private void AddLog(LogItem s)
  40. {
  41. Dispatcher.BeginInvoke(() =>
  42. {
  43. if (_mainWindowViewModel != null)
  44. {
  45. _mainWindowViewModel.LogItems.Add(s);
  46. }
  47. });
  48. }
  49. }
  50. }