diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Calculator/Implementation/Calculator.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Calculator/Implementation/Calculator.cs index 93638fa2..3e592d99 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Calculator/Implementation/Calculator.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Calculator/Implementation/Calculator.cs @@ -168,6 +168,10 @@ namespace Microsoft.Windows.Controls DisplayText = newValue.ToString(); else DisplayText = "0"; + + RoutedPropertyChangedEventArgs args = new RoutedPropertyChangedEventArgs(oldValue, newValue); + args.RoutedEvent = ValueChangedEvent; + RaiseEvent(args); } #endregion //Value @@ -236,7 +240,15 @@ namespace Microsoft.Windows.Controls if (_lastOperation == Operation.None) return; - Value = Decimal.Round(CalculateValue(_lastOperation), Precision); + try + { + Value = Decimal.Round(CalculateValue(_lastOperation), Precision); + } + catch + { + Value = null; + DisplayText = "ERROR"; + } } private void Calculate(Operation newOperation) @@ -404,7 +416,7 @@ namespace Microsoft.Windows.Controls break; } - _previousValue = Decimal.Parse(DisplayText); + Decimal.TryParse(DisplayText, out _previousValue); _showNewNumber = true; } @@ -417,6 +429,17 @@ namespace Microsoft.Windows.Controls #endregion //Methods + #region Events + + public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Bubble, typeof(RoutedPropertyChangedEventHandler), typeof(Calculator)); + public event RoutedPropertyChangedEventHandler ValueChanged + { + add { AddHandler(ValueChangedEvent, value); } + remove { RemoveHandler(ValueChangedEvent, value); } + } + + #endregion //Events + #region Commands private void ExecuteCalculatorButtonClick(object sender, ExecutedRoutedEventArgs e)