PreviewerWindowViewModel.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Collections.ObjectModel;
  2. using System.Diagnostics;
  3. using Avalonia.Threading;
  4. using ReactiveUI;
  5. namespace QuestPDF.Previewer
  6. {
  7. internal sealed class PreviewerWindowViewModel : ReactiveObject
  8. {
  9. private bool _documentContentHasLayoutOverflowIssues;
  10. public bool DocumentContentHasLayoutOverflowIssues
  11. {
  12. get => _documentContentHasLayoutOverflowIssues;
  13. set => this.RaiseAndSetIfChanged(ref _documentContentHasLayoutOverflowIssues, value);
  14. }
  15. private float _currentScroll;
  16. public float CurrentScroll
  17. {
  18. get => _currentScroll;
  19. set => this.RaiseAndSetIfChanged(ref _currentScroll, value);
  20. }
  21. private float _scrollViewportSize;
  22. public float ScrollViewportSize
  23. {
  24. get => _scrollViewportSize;
  25. set
  26. {
  27. this.RaiseAndSetIfChanged(ref _scrollViewportSize, value);
  28. VerticalScrollbarVisible = value < 1;
  29. }
  30. }
  31. private bool _verticalScrollbarVisible;
  32. public bool VerticalScrollbarVisible
  33. {
  34. get => _verticalScrollbarVisible;
  35. private set => Dispatcher.UIThread.Post(() => this.RaiseAndSetIfChanged(ref _verticalScrollbarVisible, value));
  36. }
  37. public PreviewerWindowViewModel()
  38. {
  39. CommunicationService.Instance.OnDocumentUpdated += x => DocumentContentHasLayoutOverflowIssues = x.DocumentContentHasLayoutOverflowIssues;
  40. }
  41. private static void OpenLink(string path)
  42. {
  43. using var openBrowserProcess = new Process
  44. {
  45. StartInfo = new()
  46. {
  47. UseShellExecute = true,
  48. FileName = path
  49. }
  50. };
  51. openBrowserProcess.Start();
  52. }
  53. }
  54. }