MainWindowViewModel.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System.Threading.Tasks;
  2. using MiniMvvm;
  3. namespace RenderDemo.ViewModels
  4. {
  5. public class MainWindowViewModel : ViewModelBase
  6. {
  7. private bool _drawDirtyRects;
  8. private bool _drawFps = true;
  9. private bool _drawLayoutTimeGraph;
  10. private bool _drawRenderTimeGraph;
  11. private double _width = 800;
  12. private double _height = 600;
  13. public MainWindowViewModel()
  14. {
  15. ToggleDrawDirtyRects = MiniCommand.Create(() => DrawDirtyRects = !DrawDirtyRects);
  16. ToggleDrawFps = MiniCommand.Create(() => DrawFps = !DrawFps);
  17. ToggleDrawLayoutTimeGraph = MiniCommand.Create(() => DrawLayoutTimeGraph = !DrawLayoutTimeGraph);
  18. ToggleDrawRenderTimeGraph = MiniCommand.Create(() => DrawRenderTimeGraph = !DrawRenderTimeGraph);
  19. ResizeWindow = MiniCommand.CreateFromTask(ResizeWindowAsync);
  20. }
  21. public bool DrawDirtyRects
  22. {
  23. get => _drawDirtyRects;
  24. set => RaiseAndSetIfChanged(ref _drawDirtyRects, value);
  25. }
  26. public bool DrawFps
  27. {
  28. get => _drawFps;
  29. set => RaiseAndSetIfChanged(ref _drawFps, value);
  30. }
  31. public bool DrawLayoutTimeGraph
  32. {
  33. get => _drawLayoutTimeGraph;
  34. set => RaiseAndSetIfChanged(ref _drawLayoutTimeGraph, value);
  35. }
  36. public bool DrawRenderTimeGraph
  37. {
  38. get => _drawRenderTimeGraph;
  39. set => RaiseAndSetIfChanged(ref _drawRenderTimeGraph, value);
  40. }
  41. public double Width
  42. {
  43. get => _width;
  44. set => RaiseAndSetIfChanged(ref _width, value);
  45. }
  46. public double Height
  47. {
  48. get => _height;
  49. set => RaiseAndSetIfChanged(ref _height, value);
  50. }
  51. public MiniCommand ToggleDrawDirtyRects { get; }
  52. public MiniCommand ToggleDrawFps { get; }
  53. public MiniCommand ToggleDrawLayoutTimeGraph { get; }
  54. public MiniCommand ToggleDrawRenderTimeGraph { get; }
  55. public MiniCommand ResizeWindow { get; }
  56. private async Task ResizeWindowAsync()
  57. {
  58. for (int i = 0; i < 30; i++)
  59. {
  60. Width += 10;
  61. Height += 5;
  62. await Task.Delay(10);
  63. }
  64. await Task.Delay(10);
  65. for (int i = 0; i < 30; i++)
  66. {
  67. Width -= 10;
  68. Height -= 5;
  69. await Task.Delay(10);
  70. }
  71. }
  72. }
  73. }