private void dot_Click(object sender, RoutedEventArgs e)
 {
     if (CurrentValue.Contains(".") == false)
     {
         CurrentValue = $"{CurrentValue}.";
     }
 }       // mozda ima sredjivanja
Ejemplo n.º 2
0
 public override void LoadCurrentValue(IniFile configIni)
 {
     base.LoadCurrentValue(configIni);
     CurrentValue = CurrentValue.TrimEnd('f');
     CurrentValue = CurrentValue.Contains(".") ? CurrentValue.TrimEnd('0').TrimEnd('.') : CurrentValue;
 }
Ejemplo n.º 3
0
        protected bool IsSelected(TItem item)
        {
            var key = Key(item);

            return(CurrentValue.Contains(key));
        }
        public CalcViewModel()
        {
            ClearAllCommand = new RelayCommand(() =>
            {
                CurrentValue  = "0";
                LastCalcValue = 0;
                TotalValue    = 0;
                ClearOperationStack();
                SetBothOperations(Operation.None);
            });

            ClearCommand = new RelayCommand(() =>
            {
                CurrentValue = "0";
            });

            RemoveCommand = new RelayCommand(() =>
            {
                if (CurrentValue == "0")
                {
                    return;
                }

                if (CurrentValue.Length == 1)
                {
                    CurrentValue = "0";
                    return;
                }

                CurrentValue = CurrentValue.Remove(CurrentValue.Length - 1, 1);
            });

            DivisionCommand = new RelayCommand(() => DoOperation(Operation.Division));

            MultiplicationCommand = new RelayCommand(() => DoOperation(Operation.Multiplication));

            SubtractionCommand = new RelayCommand(() => DoOperation(Operation.Subtraction));

            AdditionCommand = new RelayCommand(() => DoOperation(Operation.Addition));

            NegationCommand = new RelayCommand(() =>
            {
                if (CurrentValue == "0")
                {
                    return;
                }

                if (CurrentValue.StartsWith("-"))
                {
                    CurrentValue = CurrentValue.Remove(0, 1);
                }
                else
                {
                    CurrentValue = CurrentValue.Insert(0, "-");
                }
            });

            CommaCommand = new RelayCommand(() =>
            {
                if (CurrentValue.Contains(","))
                {
                    return;
                }

                CurrentValue += ",";
            });

            EqualsCommand = new RelayCommand(() =>
            {
                if (LastOperation != Operation.Equation)
                {
                    LastCalcValue = CurrentValueAsDouble;
                }

                CalculateCurrentValue(LastCalcValue, LastCalcOperation);
                LastOperation = Operation.Equation;
                ClearOperationStack();
            });

            DigitCommand = new RelayCommand <string>((digit) =>
            {
                if (CurrentValue == "0" || LastOperation != Operation.None)
                {
                    CurrentValue = "";
                }

                if (LastOperation == Operation.Equation)
                {
                    TotalValue = 0;
                }

                LastOperation = Operation.None;
                CurrentValue += digit;
            });
        }