Page2ViewModel.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using ReactiveUI;
  4. using Avalonia.Media;
  5. using Avalonia.Controls.Shapes;
  6. using Avalonia.Threading;
  7. using AvaloniaApplication4.Models;
  8. using Avalonia.Controls;
  9. using static System.Net.Mime.MediaTypeNames;
  10. using Avalonia.Controls.Documents;
  11. namespace AvaloniaApplication4.ViewModels
  12. {
  13. public class Page2ViewModel : ReactiveObject
  14. {
  15. public static List<string> funclis => Models.Model.funclist;
  16. public string _selectedFunclist = funclis[0];
  17. // ñâîéñòâî äëÿ îòîáðàæåíèÿ èçíà÷àëüíî âûáðàííîãî çíà÷åèÿ â ñïèñêå
  18. public List<String> Funclist
  19. {
  20. get
  21. {
  22. return funclis;
  23. }
  24. }
  25. public string Selectedfunc
  26. {
  27. get => _selectedFunclist;
  28. set
  29. {
  30. this.RaiseAndSetIfChanged(ref _selectedFunclist, value);
  31. Calculate();
  32. }
  33. }
  34. double _num1;
  35. public double Num1
  36. {
  37. get => _num1;
  38. set => this.RaiseAndSetIfChanged(ref _num1, value);
  39. }
  40. double _num2;
  41. public double Num2
  42. {
  43. get => _num2;
  44. set => this.RaiseAndSetIfChanged(ref _num2, value);
  45. }
  46. string _symb;
  47. public string Symb
  48. {
  49. get => _symb;
  50. set => this.RaiseAndSetIfChanged(ref _symb, value);
  51. }
  52. string _result ="";
  53. public string Result
  54. {
  55. get => _result;
  56. set => this.RaiseAndSetIfChanged(ref _result, value);
  57. }
  58. double res = 0;
  59. public void Calculate()
  60. {
  61. if (Selectedfunc == "Ñëîæåíèå")
  62. {
  63. res = _num1 + _num2;
  64. Result = ""+res;
  65. Symb = "+";
  66. }
  67. if (Selectedfunc == "Äåëåíèå")
  68. {
  69. if (_num1 == 0 || _num2 == 0 || (_num2 == 0 && _num1 == 0))
  70. {
  71. Result = "äåëåíèå íà íîëü";
  72. }
  73. else
  74. {
  75. res = _num1 / _num2;
  76. Result = "" + res;
  77. Symb = "/";
  78. }
  79. }
  80. if (Selectedfunc == "Óìíîæåíèå")
  81. {
  82. res = _num1 * _num2;
  83. Result = "" + res;
  84. Symb = "*";
  85. }
  86. if (Selectedfunc == "Âû÷èòàíèå")
  87. {
  88. res = _num1 - _num2;
  89. Result = "" + res;
  90. Symb = "-";
  91. }
  92. }
  93. }
  94. }