protected override void OnNavigatedTo(NavigationEventArgs e) { PointerPressed += new PointerEventHandler(T_PointerPressed); PointerReleased += new PointerEventHandler(T_PointerReleased); PointerMoved += new PointerEventHandler(T_PointerMoved); equation = e.Parameter as Equation; DrawGraph(); }
public void Operation(string operation) { if (double.TryParse(Display, out double val)) { if (val == 0) { Display = "0"; } if (!(lastOperator == "/" && Display == "0")) { if (lastAction != "+-") { if (operators.Contains(lastAction) && lastAction != "=") { Equation = Equation.Remove(Equation.Length - 1) + operation; } else if (lastAction != "exc") { if (lastAction == "=") { Equation = ""; } Equation += Display; Math(lastOperator, val); Display = result.ToString(); Equation += operation; } lastAction = operation; lastOperator = operation; } } else { ClearAll(); Equation = "Cant divide by zero!"; lastAction = "exc"; } } }
public ViewModel() { Number = new RelayCommand( (parameter) => { if (isSumDisplayed || Equation.Equals("0")) { Equation = (string)parameter; } else { Equation += parameter; } isSumDisplayed = false; RefreshCanExecutes(); }, (obj) => { return(isSumDisplayed || Equation.Length < 16); }); Point = new RelayCommand( (obj) => { if (Equation.Equals("0")) { Equation = "0."; } else { Equation += "."; } isSumDisplayed = false; RefreshCanExecutes(); }, (obj) => { return(isSumDisplayed || !Equation.Contains(".")); }); Operator = new RelayCommand( (parameter) => { if (firstOperation) { left = Double.Parse(Equation); firstOperation = false; rememberOperator = (string)parameter; HistoryEquation += left.ToString() + parameter; } else { right = Double.Parse(Equation); HistoryEquation += right.ToString() + parameter; switch (rememberOperator) { case "+": left += right; break; case "-": left -= right; break; case "*": left *= right; break; case "/": left /= right; break; } rememberOperator = (string)parameter; } Equation = left.ToString(); isSumDisplayed = true; RefreshCanExecutes(); }, (parameter) => { return(!isSumDisplayed); }); Ce = new RelayCommand( (obj) => { left = 0; HistoryEquation = ""; Equation = "0"; isSumDisplayed = false; RefreshCanExecutes(); }); C = new RelayCommand( (obj) => { right = 0; Equation = "0"; isSumDisplayed = false; RefreshCanExecutes(); }, (obj) => { return(!isSumDisplayed); }); Bcs = new RelayCommand( (obj) => { Equation = Equation.Substring(0, Equation.Length - 1); if (Equation.Length == 0) { Equation = "0"; } RefreshCanExecutes(); }, (obj) => { return(!isSumDisplayed && (Equation.Length > 1 || Equation[0] != '0')); }); }
private void operator operatorButtonClicked(Symbol op) { if (ERROR_MESSAGE.Equals(_equationText)) { changeEquationText("0" + op.ToString()); return; } var eq = new Equation(_equationText); if (eq.HasFinalOperator()) { changeEquationText(eq.ReplaceFinalOperator(op)); } else { changeEquationText(_equationText + op.ToString()); } }
private void openParenthesis() { Symbol sym = new OpenParenthesis(); if (ERROR_MESSAGE.Equals(_equationText) || "0".Equals(_equationText)) { changeEquationText(sym.ToString()); return; } var eq = new Equation(_equationText); if (!eq.HasFinalOperator()) { // Disallow a number followed by an open parenthesis return; } changeEquationText(_equationText + sym.ToString()); }
protected void OnButtonDotClicked(object sender, System.EventArgs e) { if (ERROR_MESSAGE.Equals(_equationText)) { changeEquationText("0."); return; } var eq = new Equation(_equationText); if (!eq.HasFinalOperator()) { changeEquationText(_equationText + "."); } }