AnimationsPageViewModel.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using ReactiveUI;
  3. using Avalonia.Animation;
  4. namespace RenderTest.ViewModels
  5. {
  6. public class AnimationsPageViewModel : ReactiveObject
  7. {
  8. private string _playStateText = "Pause all animations";
  9. public AnimationsPageViewModel()
  10. {
  11. ToggleGlobalPlayState = ReactiveCommand.Create(()=>TogglePlayState());
  12. }
  13. void TogglePlayState()
  14. {
  15. switch (Timing.GetGlobalPlayState())
  16. {
  17. case PlayState.Run:
  18. PlayStateText = "Resume all animations";
  19. Timing.SetGlobalPlayState(PlayState.Pause);
  20. break;
  21. case PlayState.Pause:
  22. PlayStateText = "Pause all animations";
  23. Timing.SetGlobalPlayState(PlayState.Run);
  24. break;
  25. }
  26. }
  27. public string PlayStateText
  28. {
  29. get { return _playStateText; }
  30. set { this.RaiseAndSetIfChanged(ref _playStateText, value); }
  31. }
  32. public ReactiveCommand ToggleGlobalPlayState { get; }
  33. }
  34. }