コード例 #1
0
        public void OperationSwitcher(string op, CalcViewModel cvm)
        {
            switch (op)
            {
            case "+":
                cvm.Add();
                break;

            case "-":
                cvm.Subtract();
                break;

            case "*":
                cvm.Multiply();
                break;

            case "/":
                cvm.Divide();
                break;

            case "√":
                cvm.Sqrt();
                break;

            case "±":
                cvm.Opposite();
                break;

            case "1/x":
                cvm.Inverse();
                break;

            case "%":
                cvm.PlusPercent();
                break;

            case "CE":
                cvm.Clear();
                break;

            case "C":
                cvm.ClearAll();
                break;

            case "=":
                cvm.Equal();
                break;

            case "←":
                cvm.Back();
                break;
            }
        }
コード例 #2
0
        public void KeyBoardSwitcher(string key, CalcViewModel cvm)
        {
            var local = InputLanguageManager.Current;//ru-RU

            switch (key)
            {
            case "D0":
                TxtUpdate("0");
                break;

            case "NumPad0":
                TxtUpdate("0");
                break;

            case "D1":
                TxtUpdate("1");
                break;

            case "NumPad1":
                TxtUpdate("1");
                break;

            case "D2":
                TxtUpdate("2");
                break;

            case "NumPad2":
                TxtUpdate("2");
                break;

            case "D3":
                TxtUpdate("3");
                break;

            case "NumPad3":
                TxtUpdate("3");
                break;

            case "D4":
                TxtUpdate("4");
                break;

            case "NumPad4":
                TxtUpdate("4");
                break;

            case "D5":
                TxtUpdate("5");
                break;

            case "NumPad5":
                if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                {
                    cvm.PlusPercent();
                }
                else
                {
                    TxtUpdate("5");
                }
                break;

            case "D6":
                TxtUpdate("6");
                break;

            case "NumPad6":
                TxtUpdate("6");
                break;

            case "D7":
                TxtUpdate("7");
                break;

            case "NumPad7":
                TxtUpdate("7");
                break;

            case "D8":
                if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                {
                    cvm.Multiply();
                }
                else
                {
                    TxtUpdate("8");
                }
                break;

            case "NumPad8":
                TxtUpdate("8");
                break;

            case "D9":
                TxtUpdate("9");
                break;

            case "NumPad9":
                TxtUpdate("9");
                break;

            case "Back":
                cvm.Back();
                break;

            case "Add":
                Add();
                break;

            case "OemPlus":
                if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                {
                    cvm.Add();
                }
                else
                {
                    cvm.Equal();
                }
                break;

            case "Multiply":
                Multiply();
                break;

            case "Divide":
                Divide();
                break;

            case "OemQuestion":
                if (local.CurrentInputLanguage.ToString() == "ru-RU")
                {
                    TxtUpdate(".");
                }
                else
                if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                {
                    cvm.Divide();
                }
                break;

            case "Subtract":
                cvm.Subtract();
                break;

            case "OemMinus":
                if (!(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)))
                {
                    cvm.Subtract();
                }
                break;

            case "Decimal":
                TxtUpdate(".");
                break;

            case "OemComma":
                if (local.CurrentInputLanguage.ToString() != "ru-RU")
                {
                    TxtUpdate(".");
                }
                break;

            case "OemPeriod":
                if (local.CurrentInputLanguage.ToString() != "ru-RU")
                {
                    TxtUpdate(".");
                }
                break;

            case "Return":
                cvm.Equal();
                break;
            }
        }