using Avalonia.Controls; using avaloniaPr.Models; using ReactiveUI; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace avaloniaPr.ViewModels { public class CalculatorViewModel : ViewModelBase { string textCalculator = "Выберите арифметическую операцию:"; string textButton = "Вычислить"; string selectItem = ""; double result; double oneNum; double twoNum; public string TextCalculator { get => textCalculator; set => this.RaiseAndSetIfChanged(ref textCalculator, value); } public string TextButton { get => textButton; set => this.RaiseAndSetIfChanged(ref textButton, value); } public List ListItem { get => Models.ItemsOperation.Items; } public string SV { get => selectItem; set { if (value == "Сумма") { this.RaiseAndSetIfChanged(ref selectItem, "+"); } else if (value == "Разность") { this.RaiseAndSetIfChanged(ref selectItem, "-"); } else if (value == "Умножение") { this.RaiseAndSetIfChanged(ref selectItem, "*"); } else if (value == "Деление") { this.RaiseAndSetIfChanged(ref selectItem, "/"); } } } public double OneNum { get => oneNum; set { this.RaiseAndSetIfChanged(ref oneNum, value); } } public double TwoNum { get => twoNum; set { this.RaiseAndSetIfChanged(ref twoNum, value); } } public void CommandCalculator() { switch (SV) { case "+": { result = OneNum + TwoNum; Result++; Result--; } break; case "-": { result = OneNum - TwoNum; Result++; Result--; } break; case "*": { result = OneNum * TwoNum; Result++; Result--; } break; case "/": { result = OneNum / TwoNum; Result++; Result--; } break; } } public double Result { get => result; set { this.RaiseAndSetIfChanged(ref result, value); } } } }