BezierCurveViewModel.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using FlowChartModule.绘制模块;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Threading;
  10. using Prism.Mvvm;
  11. namespace FlowChartModule.ViewModels
  12. {
  13. public class BezierCurveViewModel :BindableBase
  14. {
  15. private BezierCurveModel _curveModel;
  16. private Random _random = new Random();
  17. private DispatcherTimer _timer;
  18. public BezierCurveModel CurveModel
  19. {
  20. get { return _curveModel; }
  21. set
  22. {
  23. if ( _curveModel != value )
  24. {
  25. _curveModel = value;
  26. SetProperty(ref _curveModel, value);
  27. }
  28. }
  29. }
  30. public BezierCurveViewModel()
  31. {
  32. InitializeCurveModel();
  33. InitializeTimer();
  34. }
  35. private void InitializeCurveModel()
  36. {
  37. CurveModel = new BezierCurveModel
  38. {
  39. StartPoint = new Point(50, 100),
  40. EndPoint = new Point(350, 100),
  41. ControlPoint1 = new Point(_random.Next(100, 200), _random.Next(50, 200)),
  42. ControlPoint2 = new Point(_random.Next(200, 300), _random.Next(50, 200))
  43. };
  44. }
  45. private void InitializeTimer()
  46. {
  47. //_timer = new DispatcherTimer();
  48. //_timer.Interval = TimeSpan.FromSeconds(1);
  49. //_timer.Tick += Timer_Tick;
  50. //_timer.Start();
  51. }
  52. private void Timer_Tick(object sender, EventArgs e)
  53. {
  54. UpdateCurveModel();
  55. }
  56. private void UpdateCurveModel()
  57. {
  58. CurveModel = new BezierCurveModel
  59. {
  60. StartPoint = new Point(50, 100),
  61. EndPoint = new Point(350, 100),
  62. ControlPoint1 = new Point(_random.Next(100, 200), _random.Next(50, 200)),
  63. ControlPoint2 = new Point(_random.Next(200, 300), _random.Next(50, 200))
  64. };
  65. }
  66. }
  67. }