WPF Calculator
The Calculator control comes with the WPF Toolkit Extended. This article demonstrates how to use the Calculator control in WPF application using C# and XAML.
Adding Reference to WPF Toolkit Extended Assembly
The Calculator control is a part of the WPF Toolkit Extended and does not come with Visual Studio 2010. To use the Calculator control in your application, you must add reference to the WPFToolkit.Extended.dll assembly. You can download Extended WPF Tookit from the CodePlex or you can use the WPFToolkit.Extended.dll available with this download. All you need is the DLL. See Downloads section of this article. You can find more details in my blog Adding Reference to WPF Toolkit Extended.
Creating a Calculator
The default Calculator looks like Figure 1. Listing 1 creates a simple Calculator control.
<wpfx:Calculator Name="MathCalculator" />
Listing 1
Figure 1
Features
The Calculator control supports the following operations.
- Basic mathematical operations such as addition, subtraction, and multiplication.
- Memory operations such as clear, store, recall, M+ and M-.
- Mouse and keyboard support
Properties
The DiaplayText property represents the current value as text.
The Memory property represents the current value stored in the calculator memory.
The Precision property represents number of precision points.
The Value property represents the current number value.
string text = MathCalculator.DisplayText;
decimal d = MathCalculator.Memory;
int value = MathCalculator.Precision;
MessageBox.Show(MathCalculator.Value.ToString());
Listing 2
Summary
In this article, I discussed how we can use a Calculator control in a WPF application using C# and XAML.