예제 #1
0
        /// <summary>
        /// Parse the input and calculated the result based on expression
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private static double CalculateExpression(string input)
        {
            ExpressionCalculator exc = new ExpressionCalculator();

            return(exc.GetResult(input));
        }
예제 #2
0
        public MainViewModel()
        {
            Calculator       = new ExpressionCalculator();
            CalculateCommand = new Command {
                CanExecuteFunc = obj => true, ExecuteFunc = CalculateActionFunc
            };
            CopyCommand = new Command {
                CanExecuteFunc = obj => true, ExecuteFunc = CopyActionFunc
            };
            ClearCommand = new Command {
                CanExecuteFunc = obj => true, ExecuteFunc = ClearActionFunc
            };
            CloseCommand = new Command {
                CanExecuteFunc = obj => true, ExecuteFunc = CloseActionFunc
            };

            //KeyboardCommands
            SquareCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"({Calculation})^2"
            };
            SquareRootCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"Sqrt({Calculation})"
            };
            PiCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}{Math.PI}"
            };
            FacultyCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}!"
            };
            OpenParenthesisCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}("
            };
            PowCommand = new Command {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}^"
            };
            SevenCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}7"
            };
            FourCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}4"
            };
            OneCommand = new Command {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}1"
            };
            CloseParenthesisCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation})"
            };
            SinCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"Sin({Calculation})"
            };
            EightCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}8"
            };
            FiveCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}5"
            };
            TwoCommand = new Command {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}2"
            };
            ZeroCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}0"
            };
            CosCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"Cos({Calculation})"
            };
            NineCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}9"
            };
            SixCommand = new Command {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}6"
            };
            ThreeCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}3"
            };
            PointCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}."
            };
            TanCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"Tan({Calculation})"
            };
            DivideCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}/"
            };
            MultiplyCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}*"
            };
            MinusCommand = new Command
            {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}-"
            };
            AddCommand = new Command {
                CanExecuteFunc = obj => true, ExecuteFunc = p => Calculation = $"{Calculation}+"
            };

            ShowKeyboard = true;
        }