In This Article

Calculator Class

Represents a calculator control.

[TemplateVisualState(Name = "Focused", GroupName = "FocusStates")]
[TemplateVisualState(Name = "PointerFocused", GroupName = "FocusStates")]
[TemplateVisualState(Name = "Unfocused", GroupName = "FocusStates")]
public class Calculator : Control
Inheritance:
object Visual UIElement FrameworkElement Control object

Constructors

Calculator()

Initializes an instance of the class.

public Calculator()

Properties

AcceptsEscape

Indicates whether to accept the Escape key for clearing the calculator's current entry and value.

public bool AcceptsEscape { get; set; }

Property Value

bool:

true if the Escape key should be accepted; otherwise, false. The default value is true.

Remarks

The Shift+Del key can also be used to clear the calculator's current entry and value.

AddToMemoryCommand

The ICommand that can add to memory.

public ICommand AddToMemoryCommand { get; }

Property Value

ICommand

BackspaceCommand

The ICommand that can backspace a digit.

public ICommand BackspaceCommand { get; }

Property Value

ICommand

CalculateCommand

The ICommand that can calculate the result.

public ICommand CalculateCommand { get; }

Property Value

ICommand

ClearCommand

The ICommand that can clear the current entry and value.

public ICommand ClearCommand { get; }

Property Value

ICommand

ClearEntryCommand

The ICommand that can clear the current entry.

public ICommand ClearEntryCommand { get; }

Property Value

ICommand

ClearMemoryCommand

The ICommand that can clear memory.

public ICommand ClearMemoryCommand { get; }

Property Value

ICommand

DigitButtonStyle

The Style to use for digit buttons.

public Style? DigitButtonStyle { get; set; }

Property Value

Style

DisplayFontSize

The display font size.

public double DisplayFontSize { get; set; }

Property Value

double

DisplayText

The text that represents the calculator output.

public string DisplayText { get; }

Property Value

string:

The default value is "0".

HasDisplay

Indicates whether the calculator output is displayed.

public bool HasDisplay { get; set; }

Property Value

bool:

true if the calculator output is displayed; otherwise, false. The default value is true.

HasMemoryButtons

Indicates whether the memory buttons are displayed.

public bool HasMemoryButtons { get; set; }

Property Value

bool:

true if the memory buttons are displayed; otherwise, false. The default value is true.

InsertDecimalSeparatorCommand

The ICommand that can insert a decimal separator.

public ICommand InsertDecimalSeparatorCommand { get; }

Property Value

ICommand

InsertDigitCommand

The ICommand that can insert a digit.

public ICommand InsertDigitCommand { get; }

Property Value

ICommand

IsOutOfRange

Indicates whether the calculated value is outside the Minimum and Maximum range.

public bool IsOutOfRange { get; }

Property Value

bool:

true if the calculated value is outside the Minimum and Maximum range; otherwise, false.

See Also

Maximum

The highest possible value.

public double Maximum { get; set; }

Property Value

double

See Also

MemoryButtonStyle

The Style to use for memory buttons.

public Style? MemoryButtonStyle { get; set; }

Property Value

Style

Minimum

The lowest possible value.

public double Minimum { get; set; }

Property Value

double

See Also

OperationButtonStyle

The Style to use for operation buttons.

public Style? OperationButtonStyle { get; set; }

Property Value

Style

OperationCommand

The ICommand that can execute an operation.

public ICommand OperationCommand { get; }

Property Value

ICommand

RecallMemoryCommand

The ICommand that can recall memory.

public ICommand RecallMemoryCommand { get; }

Property Value

ICommand

SetMemoryCommand

The ICommand that can set memory.

public ICommand SetMemoryCommand { get; }

Property Value

ICommand

SubtractFromMemoryCommand

The ICommand that can subtract from memory.

public ICommand SubtractFromMemoryCommand { get; }

Property Value

ICommand

Value

The current calculated value.

public double Value { get; set; }

Property Value

double:

The default value is 0.0.

Methods

OnApplyTemplate()

When overridden in a derived class, is invoked whenever application code or internal processes call ApplyTemplate().

public override void OnApplyTemplate()

OnCreateAutomationPeer()

Returns class-specific AutomationPeer implementations for the Windows Presentation Foundation (WPF) infrastructure.

protected override AutomationPeer OnCreateAutomationPeer()

Returns

AutomationPeer:

The type-specific AutomationPeer implementation.

OnGotFocus(RoutedEventArgs)

Invoked whenever an unhandled GotFocus event reaches this element in its route.

protected override void OnGotFocus(RoutedEventArgs e)
Parameter Type Description
e RoutedEventArgs

The RoutedEventArgs that contains the event data.

OnKeyDown(KeyEventArgs)

Invoked when an unhandled System.Windows.Input.Keyboard.KeyDown attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.

protected override void OnKeyDown(KeyEventArgs e)
Parameter Type Description
e KeyEventArgs

The KeyEventArgs that contains the event data.

OnLostFocus(RoutedEventArgs)

Raises the LostFocus routed event by using the event data that is provided.

protected override void OnLostFocus(RoutedEventArgs e)
Parameter Type Description
e RoutedEventArgs

A RoutedEventArgs that contains event data. This event data must contain the identifier for the LostFocus event.

Events

ValueChanged

Occurs after the Value property value changes.

public event EventHandler? ValueChanged

Event Type

EventHandler

Fields

AcceptsEscapeProperty

Defines the AcceptsEscape property.

public static readonly DependencyProperty AcceptsEscapeProperty

DigitButtonStyleProperty

Defines the DigitButtonStyle property.

public static readonly DependencyProperty DigitButtonStyleProperty

DisplayFontSizeProperty

Defines the DisplayFontSize property.

public static readonly DependencyProperty DisplayFontSizeProperty

DisplayTextProperty

Defines the DisplayText property.

public static readonly DependencyProperty DisplayTextProperty

HasDisplayProperty

Defines the HasDisplay property.

public static readonly DependencyProperty HasDisplayProperty

HasMemoryButtonsProperty

Defines the HasMemoryButtons property.

public static readonly DependencyProperty HasMemoryButtonsProperty

IsOutOfRangeProperty

Defines the IsOutOfRange property.

public static readonly DependencyProperty IsOutOfRangeProperty

MaximumProperty

Defines the Maximum property.

public static readonly DependencyProperty MaximumProperty

MemoryButtonStyleProperty

Defines the MemoryButtonStyle property.

public static readonly DependencyProperty MemoryButtonStyleProperty

MinimumProperty

Defines the Minimum property.

public static readonly DependencyProperty MinimumProperty

OperationButtonStyleProperty

Defines the OperationButtonStyle property.

public static readonly DependencyProperty OperationButtonStyleProperty

ValueProperty

Defines the Value property.

public static readonly DependencyProperty ValueProperty

Extension Methods