Calculator WPF

Project information

Tool

Calculator WPF

Dec 2024 - Jan 2025
BUas

A simple calculator application made with XAML and WPF. I tried to mimic the Windows calculator in terms of how it looks like and how it works

Project Overview

Between December 2024 and January 2025, I developed a calculator application using Windows Presentation Foundation (WPF) with XAML and C#. This solo project, completed over a two-week period, aimed to emulate the appearance and functionality of the standard Windows calculator. While the application replicates many features of the standard view, certain functionalities, such as memory operations, have yet to be implemented.

The Challenge

Writing the backend for the calculator was more difficult than I originally estimated because I had to think about how I'm going to store the operands, the operator, and the result and then think about how I'm going to represent the result and the equation.

The frontend had some trouble with the bindings but I managed to resolve that issue. I used the MVC pattern. Creating the layout and applying styles was very interesting.

To improve the UX, I made it so that the user can also type the equation with the keyboard instead of having to click each button with the mouse. Some keys didn't have the keycodes I thought they would have based on the documentation but I managed to find a solution online.

The Solution

I'm using the decimal type to store the operands because of its accuracy and because it can convert be easily converted to an integer (e.g, 4.1 - 0.1 = 4 instead of 4.0).

I'm storing the operator as an enum value and I calculate the result based on that value. The result is then stored in the first operand which allows for chaining operations.

Project Features

  • Responsive Design
  • Keyboard and Mouse input
  • Basic operations and floating point support
  • Clear and Clear Expression
  • Styles

Technologies Used

WPF XAML C#