Overview
TheApplicationViewModel class is the central ViewModel for the Windows Calculator application. It manages the overall application state, handles navigation between different calculator modes, and coordinates interactions between specialized ViewModels.
Namespace: CalculatorApp.ManagedViewModels
Implements: INotifyPropertyChanged
Key Properties
Mode
PreviousMode and triggers mode-specific ViewModel initialization.
Supported modes:
ViewMode.Standard- Standard calculatorViewMode.Scientific- Scientific calculatorViewMode.Programmer- Programmer calculatorViewMode.DateCalculation- Date calculatorViewMode.Currency- Currency converterViewMode.Volume,ViewMode.Length, etc. - Unit converters
CalculatorViewModel
DateCalcViewModel
ConverterViewModel
GraphingCalcViewModel
IsAlwaysOnTop
DisplayNormalAlwaysOnTopOption
true when:
- Calculator is in Standard mode
- CompactOverlay is supported by the system
- Not currently in Always-on-Top mode
CategoryName
Categories
PreviousMode
Snapshot
ClearMemoryVisibility
Visibility.Visible for calculator modes, Visibility.Collapsed for other modes.
Commands
CopyCommand
PasteCommand
Methods
Initialize
mode- The initial ViewMode to set
ToggleAlwaysOnTop
width- Current window widthheight- Current window height
calculatorAlwaysOnTopLastWidth- Saved widthcalculatorAlwaysOnTopLastHeight- Saved heightcalculatorAlwaysOnTopLaunched- First launch flag
RestoreFromSnapshot
snapshot- The ApplicationSnapshot containing saved state
INotifyPropertyChanged Implementation
The ApplicationViewModel implements property change notifications automatically:PropertyChanged events when their values change, enabling XAML data binding.
Mode Navigation Flow
When theMode property changes:
PreviousModeis set to the current mode- The new mode is validated
OnModeChanged()is called, which:- Initializes the appropriate ViewModel (lazy initialization)
- Updates the
CategoryNamewith localized text - Saves the mode to local settings
- Logs telemetry events
- Updates
ClearMemoryVisibility
Usage Example
Thread Safety
Property changes and mode navigation should occur on the UI thread. TheToggleAlwaysOnTop method uses async/await for view mode transitions.
See Also
- StandardCalculatorViewModel - Calculator operations
- DateCalculatorViewModel - Date calculations
- UnitConverterViewModel - Unit conversions