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 Calculator class.

public Calculator()

Properties

AcceptsEscape

Gets or sets 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

Gets the ICommand that can add to memory.

public ICommand AddToMemoryCommand { get; }

Property Value

ICommand:

The ICommand that can add to memory.

BackspaceCommand

Gets the ICommand that can backspace a digit.

public ICommand BackspaceCommand { get; }

Property Value

ICommand:

The ICommand that can backspace a digit.

CalculateCommand

Gets the ICommand that can calculate the result.

public ICommand CalculateCommand { get; }

Property Value

ICommand:

The ICommand that can calculate the result.

ClearCommand

Gets the ICommand that can clear the current entry and value.

public ICommand ClearCommand { get; }

Property Value

ICommand:

The ICommand that can clear the current entry and value.

ClearEntryCommand

Gets the ICommand that can clear the current entry.

public ICommand ClearEntryCommand { get; }

Property Value

ICommand:

The ICommand that can clear the current entry.

ClearMemoryCommand

Gets the ICommand that can clear memory.

public ICommand ClearMemoryCommand { get; }

Property Value

ICommand:

The ICommand that can clear memory.

DigitButtonStyle

Gets or sets the Style to use for digit buttons.

public Style DigitButtonStyle { get; set; }

Property Value

Style:

The Style to use for digit buttons.

DisplayFontSize

Gets or sets the display font size.

public double DisplayFontSize { get; set; }

Property Value

double:

The display font size.

DisplayText

Gets the text that represents the calculator output.

public string DisplayText { get; }

Property Value

string:

The text that represents the calculator output. The default value is "0".

HasDisplay

Gets or sets 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

Gets or sets 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

Gets the ICommand that can insert a decimal separator.

public ICommand InsertDecimalSeparatorCommand { get; }

Property Value

ICommand:

The ICommand that can insert a decimal separator.

InsertDigitCommand

Gets the ICommand that can insert a digit.

public ICommand InsertDigitCommand { get; }

Property Value

ICommand:

The ICommand that can insert a digit.

IsOutOfRange

Gets 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

Gets or sets the highest possible value.

public double Maximum { get; set; }

Property Value

double:

The highest possible value.

See Also

MemoryButtonStyle

Gets or sets the Style to use for memory buttons.

public Style MemoryButtonStyle { get; set; }

Property Value

Style:

The Style to use for memory buttons.

Minimum

Gets or sets the lowest possible value.

public double Minimum { get; set; }

Property Value

double:

The lowest possible value.

See Also

OperationButtonStyle

Gets or sets the Style to use for operation buttons.

public Style OperationButtonStyle { get; set; }

Property Value

Style:

The Style to use for operation buttons.

OperationCommand

Gets the ICommand that can execute an operation.

public ICommand OperationCommand { get; }

Property Value

ICommand:

The ICommand that can execute an operation.

RecallMemoryCommand

Gets the ICommand that can recall memory.

public ICommand RecallMemoryCommand { get; }

Property Value

ICommand:

The ICommand that can recall memory.

SetMemoryCommand

Gets the ICommand that can set memory.

public ICommand SetMemoryCommand { get; }

Property Value

ICommand:

The ICommand that can set memory.

SubtractFromMemoryCommand

Gets the ICommand that can subtract from memory.

public ICommand SubtractFromMemoryCommand { get; }

Property Value

ICommand:

The ICommand that can subtract from memory.

Value

Gets or sets the current calculated value.

public double Value { get; set; }

Property Value

double:

The current calculated value. The default value is 0.0.

Methods

OnApplyTemplate()

Invoked whenever application code or internal processes call ApplyTemplate.

public override void OnApplyTemplate()

OnCreateAutomationPeer()

Returns an AutomationPeer object for this control instance.

protected override AutomationPeer OnCreateAutomationPeer()

Returns

AutomationPeer:

An AutomationPeer instance.

OnGotFocus(RoutedEventArgs)

Occurs when the control gains focus.

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

The RoutedEventArgs that contains the event data.

OnKeyDown(KeyEventArgs)

Occurs when a key is pressed.

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

The KeyEventArgs that contains the event data.

OnLostFocus(RoutedEventArgs)

Occurs when the control loses focus.

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

The RoutedEventArgs that contains the event data.

Events

ValueChanged

Occurs after the Value property value changes.

public event EventHandler ValueChanged

Event Type

EventHandler

Fields

AcceptsEscapeProperty

Identifies the AcceptsEscape dependency property. This field is read-only.

public static readonly DependencyProperty AcceptsEscapeProperty

DigitButtonStyleProperty

Identifies the DigitButtonStyle dependency property. This field is read-only.

public static readonly DependencyProperty DigitButtonStyleProperty

DisplayFontSizeProperty

Identifies the DisplayFontSize dependency property. This field is read-only.

public static readonly DependencyProperty DisplayFontSizeProperty

DisplayTextProperty

Identifies the DisplayText dependency property. This field is read-only.

public static readonly DependencyProperty DisplayTextProperty

HasDisplayProperty

Identifies the HasDisplay dependency property. This field is read-only.

public static readonly DependencyProperty HasDisplayProperty

HasMemoryButtonsProperty

Identifies the HasMemoryButtons dependency property. This field is read-only.

public static readonly DependencyProperty HasMemoryButtonsProperty

IsOutOfRangeProperty

Identifies the IsOutOfRange dependency property. This field is read-only.

public static readonly DependencyProperty IsOutOfRangeProperty

MaximumProperty

Identifies the Maximum dependency property. This field is read-only.

public static readonly DependencyProperty MaximumProperty

MemoryButtonStyleProperty

Identifies the MemoryButtonStyle dependency property. This field is read-only.

public static readonly DependencyProperty MemoryButtonStyleProperty

MinimumProperty

Identifies the Minimum dependency property. This field is read-only.

public static readonly DependencyProperty MinimumProperty

OperationButtonStyleProperty

Identifies the OperationButtonStyle dependency property. This field is read-only.

public static readonly DependencyProperty OperationButtonStyleProperty

ValueProperty

Identifies the Value dependency property. This field is read-only.

public static readonly DependencyProperty ValueProperty