Browse Source

Calculator: added Precision proeprty to user can specify to what precision to round results to.

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
a94adadbaf
  1. 23
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Calculator/Implementation/Calculator.cs

23
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Calculator/Implementation/Calculator.cs

@ -126,26 +126,25 @@ namespace Microsoft.Windows.Controls
#region Memory #region Memory
public static readonly DependencyProperty MemoryProperty = DependencyProperty.Register("Memory", typeof(decimal), typeof(Calculator), new UIPropertyMetadata(default(decimal), OnMemoryChanged)); public static readonly DependencyProperty MemoryProperty = DependencyProperty.Register("Memory", typeof(decimal), typeof(Calculator), new UIPropertyMetadata(default(decimal)));
public decimal Memory public decimal Memory
{ {
get { return (decimal)GetValue(MemoryProperty); } get { return (decimal)GetValue(MemoryProperty); }
set { SetValue(MemoryProperty, value); } set { SetValue(MemoryProperty, value); }
} }
private static void OnMemoryChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) #endregion //Memory
{
Calculator calculator = o as Calculator;
if (calculator != null)
calculator.OnMemoryChanged((decimal)e.OldValue, (decimal)e.NewValue);
}
protected virtual void OnMemoryChanged(decimal oldValue, decimal newValue) #region Precision
public static readonly DependencyProperty PrecisionProperty = DependencyProperty.Register("Precision", typeof(int), typeof(Calculator), new UIPropertyMetadata(6));
public int Precision
{ {
// TODO: Add your property changed side-effects. Descendants can override as well. get { return (int)GetValue(PrecisionProperty); }
} set { SetValue(PrecisionProperty, value); }
}
#endregion //Memory #endregion //Precision
#region Value #region Value
@ -234,7 +233,7 @@ namespace Microsoft.Windows.Controls
if (_lastOperation == Operation.None) if (_lastOperation == Operation.None)
return; return;
Value = CalculateValue(_lastOperation); Value = Decimal.Round(CalculateValue(_lastOperation), Precision);
} }
private void Calculate(Operation newOperation) private void Calculate(Operation newOperation)

Loading…
Cancel
Save