4 changed files with 827 additions and 0 deletions
@ -0,0 +1,340 @@ |
|||
using System; |
|||
using System.Windows; |
|||
using System.Windows.Controls; |
|||
using System.Windows.Input; |
|||
using System.Windows.Media; |
|||
using System.Windows.Threading; |
|||
|
|||
namespace Microsoft.Windows.Controls |
|||
{ |
|||
public static class CalculatorCommands |
|||
{ |
|||
private static RoutedCommand _calculatorButtonClickCommand = new RoutedCommand(); |
|||
public static RoutedCommand CalculatorButtonClick |
|||
{ |
|||
get { return _calculatorButtonClickCommand; } |
|||
} |
|||
} |
|||
|
|||
public class Calculator : Control |
|||
{ |
|||
private ContentControl _buttonPanel; |
|||
private readonly DispatcherTimer _timer; |
|||
private Button _calculatorButton; |
|||
|
|||
#region Properties
|
|||
|
|||
public ICommand CalculaterButtonClickCommand { get; private set; } |
|||
|
|||
#region CalculatorButtonType
|
|||
|
|||
public static readonly DependencyProperty CalculatorButtonTypeProperty = DependencyProperty.RegisterAttached("CalculatorButtonType", typeof(CalculatorButtonType), typeof(Calculator), new UIPropertyMetadata(CalculatorButtonType.None, OnCalculatorButtonTypeChanged)); |
|||
public static CalculatorButtonType GetCalculatorButtonType(DependencyObject target) |
|||
{ |
|||
return (CalculatorButtonType)target.GetValue(CalculatorButtonTypeProperty); |
|||
} |
|||
public static void SetCalculatorButtonType(DependencyObject target, CalculatorButtonType value) |
|||
{ |
|||
target.SetValue(CalculatorButtonTypeProperty, value); |
|||
} |
|||
private static void OnCalculatorButtonTypeChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) |
|||
{ |
|||
OnCalculatorButtonTypeChanged(o, (CalculatorButtonType)e.OldValue, (CalculatorButtonType)e.NewValue); |
|||
} |
|||
private static void OnCalculatorButtonTypeChanged(DependencyObject o, CalculatorButtonType oldValue, CalculatorButtonType newValue) |
|||
{ |
|||
Button button = o as Button; |
|||
button.CommandParameter = newValue; |
|||
button.Content = GetCalculatorButtonContent(newValue); |
|||
} |
|||
|
|||
#endregion //CalculatorButtonType
|
|||
|
|||
|
|||
|
|||
#region Value
|
|||
|
|||
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(decimal), typeof(Calculator), new UIPropertyMetadata(default(decimal), OnValueChanged)); |
|||
public decimal Value |
|||
{ |
|||
get { return (decimal)GetValue(ValueProperty); } |
|||
set { SetValue(ValueProperty, value); } |
|||
} |
|||
|
|||
private static void OnValueChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) |
|||
{ |
|||
Calculator calculator = o as Calculator; |
|||
if (calculator != null) |
|||
calculator.OnValueChanged((decimal)e.OldValue, (decimal)e.NewValue); |
|||
} |
|||
|
|||
protected virtual void OnValueChanged(decimal oldValue, decimal newValue) |
|||
{ |
|||
// TODO: Add your property changed side-effects. Descendants can override as well.
|
|||
} |
|||
|
|||
#endregion //Value
|
|||
|
|||
#endregion //Properties
|
|||
|
|||
#region Constructors
|
|||
|
|||
static Calculator() |
|||
{ |
|||
DefaultStyleKeyProperty.OverrideMetadata(typeof(Calculator), new FrameworkPropertyMetadata(typeof(Calculator))); |
|||
} |
|||
|
|||
public Calculator() |
|||
{ |
|||
_timer = new DispatcherTimer(); |
|||
_timer.Interval = TimeSpan.FromMilliseconds(100); |
|||
_timer.Tick += Timer_Tick; |
|||
|
|||
CommandBindings.Add(new CommandBinding(CalculatorCommands.CalculatorButtonClick, ExecuteCalculatorButtonClick)); |
|||
AddHandler(MouseDownEvent, new MouseButtonEventHandler(Calculator_OnMouseDown), true); |
|||
} |
|||
|
|||
#endregion //Constructors
|
|||
|
|||
#region Base Class Overrides
|
|||
|
|||
public override void OnApplyTemplate() |
|||
{ |
|||
base.OnApplyTemplate(); |
|||
|
|||
_buttonPanel = (ContentControl)GetTemplateChild("PART_CalculatorButtonPanel"); |
|||
} |
|||
|
|||
protected override void OnTextInput(TextCompositionEventArgs e) |
|||
{ |
|||
var buttonType = GetCalculatorButtonTypeFromText(e.Text); |
|||
|
|||
AnimateCalculatorButtonClick(buttonType); |
|||
} |
|||
|
|||
private void AnimateCalculatorButtonClick(CalculatorButtonType buttonType) |
|||
{ |
|||
_calculatorButton = FindButtonByCalculatorButtonType(_buttonPanel, buttonType); |
|||
if (_calculatorButton != null) |
|||
{ |
|||
VisualStateManager.GoToState(_calculatorButton, "Pressed", true); |
|||
_timer.Start(); |
|||
} |
|||
} |
|||
|
|||
private CalculatorButtonType GetCalculatorButtonTypeFromText(string text) |
|||
{ |
|||
switch (text) |
|||
{ |
|||
case "0": return CalculatorButtonType.Zero; |
|||
case "1": return CalculatorButtonType.One; |
|||
case "2": return CalculatorButtonType.Two; |
|||
case "3": return CalculatorButtonType.Three; |
|||
case "4": return CalculatorButtonType.Four; |
|||
case "5": return CalculatorButtonType.Five; |
|||
case "6": return CalculatorButtonType.Six; |
|||
case "7": return CalculatorButtonType.Seven; |
|||
case "8": return CalculatorButtonType.Eight; |
|||
case "9": return CalculatorButtonType.Nine; |
|||
case "%": return CalculatorButtonType.Percent; |
|||
case "+": return CalculatorButtonType.Add; |
|||
case "-": return CalculatorButtonType.Subtract; |
|||
case "*": return CalculatorButtonType.Mul; |
|||
case "/": |
|||
case ":": return CalculatorButtonType.Div; |
|||
case " ": |
|||
case "\r": |
|||
case "=": return CalculatorButtonType.Equal; |
|||
case "\b": return CalculatorButtonType.Back; |
|||
} |
|||
|
|||
//check for the escape key
|
|||
if (text == ((char)27).ToString()) |
|||
return CalculatorButtonType.Clear; |
|||
|
|||
return CalculatorButtonType.None; |
|||
} |
|||
|
|||
#endregion //Base Class Overrides
|
|||
|
|||
#region Event Handlers
|
|||
|
|||
private void Calculator_OnMouseDown(object sender, MouseButtonEventArgs e) |
|||
{ |
|||
Focus(); |
|||
} |
|||
|
|||
void Timer_Tick(object sender, EventArgs e) |
|||
{ |
|||
VisualStateManager.GoToState(_calculatorButton, _calculatorButton.IsMouseOver ? "MouseOver" : "Normal", true); |
|||
_timer.Stop(); |
|||
} |
|||
|
|||
#endregion //Event Handlers
|
|||
|
|||
#region Methods
|
|||
|
|||
public static Button FindButtonByCalculatorButtonType(DependencyObject parent, CalculatorButtonType type) |
|||
{ |
|||
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++) |
|||
{ |
|||
var child = VisualTreeHelper.GetChild(parent, i); |
|||
|
|||
object buttonType = child.GetValue(Button.CommandParameterProperty); |
|||
|
|||
if (buttonType != null && (CalculatorButtonType)buttonType == type) |
|||
{ |
|||
return child as Button; |
|||
} |
|||
else |
|||
{ |
|||
var result = FindButtonByCalculatorButtonType(child, type); |
|||
|
|||
if (result != null) |
|||
return result; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
private static string GetCalculatorButtonContent(CalculatorButtonType type) |
|||
{ |
|||
string content = string.Empty; |
|||
switch (type) |
|||
{ |
|||
case CalculatorButtonType.Add: |
|||
content = "+"; |
|||
break; |
|||
case CalculatorButtonType.Back: |
|||
content = "Back"; |
|||
break; |
|||
case CalculatorButtonType.Cancel: |
|||
content = "CE"; |
|||
break; |
|||
case CalculatorButtonType.Clear: |
|||
content = "C"; |
|||
break; |
|||
case CalculatorButtonType.Decimal: |
|||
content = "."; |
|||
break; |
|||
case CalculatorButtonType.Div: |
|||
content = "/"; |
|||
break; |
|||
case CalculatorButtonType.Eight: |
|||
content = "8"; |
|||
break; |
|||
case CalculatorButtonType.Equal: |
|||
content = "="; |
|||
break; |
|||
case CalculatorButtonType.Five: |
|||
content = "5"; |
|||
break; |
|||
case CalculatorButtonType.Four: |
|||
content = "4"; |
|||
break; |
|||
case CalculatorButtonType.Fract: |
|||
content = "1/x"; |
|||
break; |
|||
case CalculatorButtonType.MAdd: |
|||
content = "M+"; |
|||
break; |
|||
case CalculatorButtonType.MC: |
|||
content = "MC"; |
|||
break; |
|||
case CalculatorButtonType.MR: |
|||
content = "MR"; |
|||
break; |
|||
case CalculatorButtonType.MS: |
|||
content = "MS"; |
|||
break; |
|||
case CalculatorButtonType.MSub: |
|||
content = "M-"; |
|||
break; |
|||
case CalculatorButtonType.Mul: |
|||
content = "*"; |
|||
break; |
|||
case CalculatorButtonType.Nine: |
|||
content = "9"; |
|||
break; |
|||
case CalculatorButtonType.None: |
|||
break; |
|||
case CalculatorButtonType.One: |
|||
content = "1"; |
|||
break; |
|||
case CalculatorButtonType.Percent: |
|||
content = "%"; |
|||
break; |
|||
case CalculatorButtonType.Seven: |
|||
content = "7"; |
|||
break; |
|||
case CalculatorButtonType.Sign: |
|||
content = "+/-"; |
|||
break; |
|||
case CalculatorButtonType.Six: |
|||
content = "6"; |
|||
break; |
|||
case CalculatorButtonType.Sqrt: |
|||
content = "Sqrt"; |
|||
break; |
|||
case CalculatorButtonType.Subtract: |
|||
content = "-"; |
|||
break; |
|||
case CalculatorButtonType.Three: |
|||
content = "3"; |
|||
break; |
|||
case CalculatorButtonType.Two: |
|||
content = "2"; |
|||
break; |
|||
case CalculatorButtonType.Zero: |
|||
content = "0"; |
|||
break; |
|||
} |
|||
return content; |
|||
} |
|||
|
|||
#endregion //Methods
|
|||
|
|||
#region Commands
|
|||
|
|||
private void ExecuteCalculatorButtonClick(object sender, ExecutedRoutedEventArgs e) |
|||
{ |
|||
|
|||
} |
|||
|
|||
#endregion //Commands
|
|||
|
|||
|
|||
public enum CalculatorButtonType |
|||
{ |
|||
Add, |
|||
Back, |
|||
Cancel, |
|||
Clear, |
|||
Decimal, |
|||
Div, |
|||
Eight, |
|||
Equal, |
|||
Five, |
|||
Four, |
|||
Fract, |
|||
MAdd, |
|||
MC, |
|||
MR, |
|||
MS, |
|||
MSub, |
|||
Mul, |
|||
Nine, |
|||
None, |
|||
One, |
|||
Percent, |
|||
Seven, |
|||
Sign, |
|||
Six, |
|||
Sqrt, |
|||
Subtract, |
|||
Three, |
|||
Two, |
|||
Zero |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,481 @@ |
|||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:local="clr-namespace:Microsoft.Windows.Controls"> |
|||
|
|||
<Style x:Key="CalculatorOperatorButtonStyle" TargetType="{x:Type Button}"> |
|||
<Setter Property="Focusable" Value="False"/> |
|||
<Setter Property="Foreground" Value="#FF5B636E"/> |
|||
<Setter Property="Template"> |
|||
<Setter.Value> |
|||
<ControlTemplate TargetType="{x:Type Button}"> |
|||
<Grid x:Name="Control"> |
|||
<VisualStateManager.VisualStateGroups> |
|||
<VisualStateGroup x:Name="CommonStates"> |
|||
<VisualState x:Name="Normal"/> |
|||
<VisualState x:Name="MouseOver"> |
|||
<Storyboard> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_Default" Storyboard.TargetProperty="Opacity" To="0"/> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_MouseOver" Storyboard.TargetProperty="Opacity" To="1"/> |
|||
</Storyboard> |
|||
</VisualState> |
|||
<VisualState x:Name="Pressed"> |
|||
<Storyboard> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_Default" Storyboard.TargetProperty="Opacity" To="0"/> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_Pressed" Storyboard.TargetProperty="Opacity" To="1"/> |
|||
</Storyboard> |
|||
</VisualState> |
|||
<VisualState x:Name="Disabled"> |
|||
<Storyboard> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_Default" Storyboard.TargetProperty="Opacity" To=".5"/> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="Opacity" To=".5"/> |
|||
</Storyboard> |
|||
</VisualState> |
|||
</VisualStateGroup> |
|||
<VisualStateGroup x:Name="MemoryStates"> |
|||
<VisualState x:Name="EmptyMemory"/> |
|||
<VisualState x:Name="MemoryAssigned"> |
|||
<Storyboard> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_Border1" Storyboard.TargetProperty="Opacity" To="0"/> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_Border2" Storyboard.TargetProperty="Opacity" To="1"/> |
|||
</Storyboard> |
|||
</VisualState> |
|||
</VisualStateGroup> |
|||
</VisualStateManager.VisualStateGroups> |
|||
<Border Background="White" BorderBrush="{x:Null}" BorderThickness="0" CornerRadius="2" Margin="0,0,0,-1" Opacity="0.5"/> |
|||
<Grid x:Name="PART_Default"> |
|||
<Border BorderThickness="0" CornerRadius="2" Background="#FF9CA2AB"> |
|||
<Grid> |
|||
<Border x:Name="PART_Border1" BorderThickness="0" CornerRadius="1" Margin="1"> |
|||
<Border.Background> |
|||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
|||
<GradientStop Color="#FFEDF1F7" Offset="0"/> |
|||
<GradientStop Color="#FFD5DBE3" Offset="1"/> |
|||
</LinearGradientBrush> |
|||
</Border.Background> |
|||
<Border BorderThickness="0" CornerRadius="1" Margin="2"> |
|||
<Border.Background> |
|||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
|||
<GradientStop Color="#FFEDF1F7" Offset="0"/> |
|||
<GradientStop Color="#FFD5DBE3" Offset="1"/> |
|||
</LinearGradientBrush> |
|||
</Border.Background> |
|||
</Border> |
|||
</Border> |
|||
<Border x:Name="PART_Border2" BorderThickness="0" CornerRadius="1" Margin="1" Opacity="0"> |
|||
<Border.Background> |
|||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
|||
<GradientStop Color="#FF9CA2AB" Offset="0"/> |
|||
<GradientStop Color="#FF9CA2AB" Offset="1"/> |
|||
</LinearGradientBrush> |
|||
</Border.Background> |
|||
<Border BorderThickness="0" CornerRadius="1" Margin="2"> |
|||
<Border.Background> |
|||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
|||
<GradientStop Color="#FFEDF1F7" Offset="0"/> |
|||
<GradientStop Color="#FFD5DBE3" Offset="1"/> |
|||
</LinearGradientBrush> |
|||
</Border.Background> |
|||
</Border> |
|||
</Border> |
|||
</Grid> |
|||
</Border> |
|||
</Grid> |
|||
<Grid x:Name="PART_MouseOver" Opacity="0"> |
|||
<Border BorderThickness="0" CornerRadius="2" Background="#FF9CA2AB"> |
|||
<Border BorderThickness="0" CornerRadius="1" Margin="1"> |
|||
<Border.Background> |
|||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
|||
<GradientStop Color="#FFFDFEFF" Offset="0"/> |
|||
<GradientStop Color="#FFD9DFE8" Offset="1"/> |
|||
</LinearGradientBrush> |
|||
</Border.Background> |
|||
</Border> |
|||
</Border> |
|||
</Grid> |
|||
<Grid x:Name="PART_Pressed" Opacity="0"> |
|||
<Border BorderThickness="0" CornerRadius="2" Background="#FF90959D"> |
|||
<Border BorderThickness="0" CornerRadius="1" Margin="1" Background="#FFB5BBC5"/> |
|||
</Border> |
|||
</Grid> |
|||
<ContentPresenter x:Name="contentPresenter" |
|||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" |
|||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" |
|||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> |
|||
</Grid> |
|||
</ControlTemplate> |
|||
</Setter.Value> |
|||
</Setter> |
|||
</Style> |
|||
|
|||
<Style x:Key="CalculatorClearButtonStyle" TargetType="{x:Type Button}"> |
|||
<Setter Property="Focusable" Value="False"/> |
|||
<Setter Property="Foreground" Value="#FFBF5254"/> |
|||
<Setter Property="Template"> |
|||
<Setter.Value> |
|||
<ControlTemplate TargetType="{x:Type Button}"> |
|||
<Grid x:Name="Control"> |
|||
<VisualStateManager.VisualStateGroups> |
|||
<VisualStateGroup x:Name="CommonStates"> |
|||
<VisualState x:Name="Normal"/> |
|||
<VisualState x:Name="MouseOver"> |
|||
<Storyboard> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_Default" Storyboard.TargetProperty="Opacity" To="0"/> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_MouseOver" Storyboard.TargetProperty="Opacity" To="1"/> |
|||
</Storyboard> |
|||
</VisualState> |
|||
<VisualState x:Name="Pressed"> |
|||
<Storyboard> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_Default" Storyboard.TargetProperty="Opacity" To="0"/> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_Pressed" Storyboard.TargetProperty="Opacity" To="1"/> |
|||
</Storyboard> |
|||
</VisualState> |
|||
<VisualState x:Name="Disabled"> |
|||
<Storyboard> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_Default" Storyboard.TargetProperty="Opacity" To=".5"/> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="Opacity" To=".5"/> |
|||
</Storyboard> |
|||
</VisualState> |
|||
</VisualStateGroup> |
|||
</VisualStateManager.VisualStateGroups> |
|||
<Border Background="White" BorderBrush="{x:Null}" BorderThickness="0" CornerRadius="2" Margin="0,0,0,-1" Opacity="0.5"/> |
|||
<Grid x:Name="PART_Default"> |
|||
<Border BorderThickness="0" CornerRadius="2"> |
|||
<Border.Background> |
|||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
|||
<GradientStop Color="#FFC19497" Offset="0"/> |
|||
<GradientStop Color="#FFA67D80" Offset="1"/> |
|||
</LinearGradientBrush> |
|||
</Border.Background> |
|||
<Border BorderThickness="0" CornerRadius="1" Margin="1"> |
|||
<Border.Background> |
|||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
|||
<GradientStop Color="#FFFDB8B8" Offset="0"/> |
|||
<GradientStop Color="#FFF39998" Offset="1"/> |
|||
</LinearGradientBrush> |
|||
</Border.Background> |
|||
</Border> |
|||
</Border> |
|||
</Grid> |
|||
<Grid x:Name="PART_MouseOver" Opacity="0"> |
|||
<Border BorderThickness="0" CornerRadius="2"> |
|||
<Border.Background> |
|||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
|||
<GradientStop Color="#FFC19497" Offset="0"/> |
|||
<GradientStop Color="#FFA67D80" Offset="1"/> |
|||
</LinearGradientBrush> |
|||
</Border.Background> |
|||
<Border BorderThickness="0" CornerRadius="1" Margin="1"> |
|||
<Border.Background> |
|||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
|||
<GradientStop Color="#FFFEC9C9" Offset="0"/> |
|||
<GradientStop Color="#FFEAA4A3" Offset="1"/> |
|||
</LinearGradientBrush> |
|||
</Border.Background> |
|||
</Border> |
|||
</Border> |
|||
</Grid> |
|||
<Grid x:Name="PART_Pressed" Opacity="0"> |
|||
<Border BorderThickness="0" CornerRadius="2" Background="#FF9B6F72"> |
|||
<Border BorderThickness="0" CornerRadius="1" Margin="1" Background="#FFE69197"/> |
|||
</Border> |
|||
</Grid> |
|||
<ContentPresenter x:Name="contentPresenter" |
|||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" |
|||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" |
|||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> |
|||
</Grid> |
|||
</ControlTemplate> |
|||
</Setter.Value> |
|||
</Setter> |
|||
</Style> |
|||
|
|||
<Style x:Key="CalculatorDigitButtonStyle" TargetType="{x:Type Button}"> |
|||
<Setter Property="Focusable" Value="False" /> |
|||
<Setter Property="Foreground" Value="#FF2A313A"/> |
|||
<Setter Property="Template"> |
|||
<Setter.Value> |
|||
<ControlTemplate TargetType="{x:Type Button}"> |
|||
<Grid x:Name="Control"> |
|||
<VisualStateManager.VisualStateGroups> |
|||
<VisualStateGroup x:Name="CommonStates"> |
|||
<VisualState x:Name="Normal"/> |
|||
<VisualState x:Name="MouseOver"> |
|||
<Storyboard> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_Default" Storyboard.TargetProperty="Opacity" To="0"/> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_MouseOver" Storyboard.TargetProperty="Opacity" To="1"/> |
|||
</Storyboard> |
|||
</VisualState> |
|||
<VisualState x:Name="Pressed"> |
|||
<Storyboard> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_Default" Storyboard.TargetProperty="Opacity" To="0"/> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_Pressed" Storyboard.TargetProperty="Opacity" To="1"/> |
|||
</Storyboard> |
|||
</VisualState> |
|||
<VisualState x:Name="Disabled"> |
|||
<Storyboard> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="PART_Default" Storyboard.TargetProperty="Opacity" To=".5"/> |
|||
<DoubleAnimation Duration="0" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="Opacity" To=".5"/> |
|||
</Storyboard> |
|||
</VisualState> |
|||
</VisualStateGroup> |
|||
</VisualStateManager.VisualStateGroups> |
|||
<Border BorderBrush="{x:Null}" BorderThickness="0" Background="White" CornerRadius="3" Margin="0,0,0,-1" Opacity="0.5"/> |
|||
<Grid x:Name="PART_Default"> |
|||
<Border BorderThickness="0" CornerRadius="2"> |
|||
<Border.Background> |
|||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
|||
<GradientStop Color="#FFA9AAAB" Offset="0"/> |
|||
<GradientStop Color="#FF98999A" Offset="1"/> |
|||
</LinearGradientBrush> |
|||
</Border.Background> |
|||
<Border BorderThickness="0" CornerRadius="1" Margin="1"> |
|||
<Border.Background> |
|||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
|||
<GradientStop Color="#FFF6F7F7" Offset="0"/> |
|||
<GradientStop Color="#FFDEE0E2" Offset="1"/> |
|||
</LinearGradientBrush> |
|||
</Border.Background> |
|||
</Border> |
|||
</Border> |
|||
</Grid> |
|||
<Grid x:Name="PART_MouseOver" Opacity="0"> |
|||
<Border BorderThickness="0" CornerRadius="2"> |
|||
<Border.Background> |
|||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
|||
<GradientStop Color="#FFA9AAAB" Offset="0"/> |
|||
<GradientStop Color="#FF98999A" Offset="1"/> |
|||
</LinearGradientBrush> |
|||
</Border.Background> |
|||
<Border BorderThickness="0" CornerRadius="1" Margin="1"> |
|||
<Border.Background> |
|||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
|||
<GradientStop Color="#FFFCFCFC" Offset="0"/> |
|||
<GradientStop Color="#FFEEEFF2" Offset="1"/> |
|||
</LinearGradientBrush> |
|||
</Border.Background> |
|||
</Border> |
|||
</Border> |
|||
</Grid> |
|||
<Grid x:Name="PART_Pressed" Opacity="0"> |
|||
<Border BorderThickness="0" CornerRadius="2" Background="#FF87888A"> |
|||
<Border BorderThickness="0" CornerRadius="1" Margin="1" Background="#FFB5BBC5"/> |
|||
</Border> |
|||
</Grid> |
|||
<ContentPresenter x:Name="contentPresenter" |
|||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" |
|||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" |
|||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> |
|||
</Grid> |
|||
</ControlTemplate> |
|||
</Setter.Value> |
|||
</Setter> |
|||
</Style> |
|||
|
|||
|
|||
<ControlTemplate x:Key="CalculatorButtonPanel" TargetType="{x:Type ContentControl}"> |
|||
<Grid> |
|||
<Grid.ColumnDefinitions> |
|||
<ColumnDefinition/> |
|||
<ColumnDefinition Width="3"/> |
|||
<ColumnDefinition/> |
|||
<ColumnDefinition Width="3"/> |
|||
<ColumnDefinition/> |
|||
<ColumnDefinition Width="3"/> |
|||
<ColumnDefinition/> |
|||
<ColumnDefinition Width="3"/> |
|||
<ColumnDefinition/> |
|||
</Grid.ColumnDefinitions> |
|||
<Grid.RowDefinitions> |
|||
<RowDefinition/> |
|||
<RowDefinition Height="3"/> |
|||
<RowDefinition/> |
|||
<RowDefinition Height="3"/> |
|||
<RowDefinition/> |
|||
<RowDefinition Height="3"/> |
|||
<RowDefinition/> |
|||
<RowDefinition Height="3"/> |
|||
<RowDefinition/> |
|||
<RowDefinition Height="3"/> |
|||
<RowDefinition/> |
|||
</Grid.RowDefinitions> |
|||
<Button Grid.Column="0" Grid.Row="0" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="MC" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorOperatorButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="2" Grid.Row="0" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="MR" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorOperatorButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="4" Grid.Row="0" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Back" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorOperatorButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="6" Grid.Row="0" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Cancel" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorClearButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="8" Grid.Row="0" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Clear" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorClearButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="0" Grid.Row="2" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="MS" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorOperatorButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="2" Grid.Row="2" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="MAdd" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorOperatorButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="4" Grid.Row="2" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="MSub" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorOperatorButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="6" Grid.Row="2" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Sign" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorOperatorButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="8" Grid.Row="2" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Sqrt" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorOperatorButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="0" Grid.Row="4" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Seven" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorDigitButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="2" Grid.Row="4" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Eight" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorDigitButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="4" Grid.Row="4" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Nine" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorDigitButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="6" Grid.Row="4" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Div" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorOperatorButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="8" Grid.Row="4" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Percent" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorOperatorButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="0" Grid.Row="6" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Four" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorDigitButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="2" Grid.Row="6" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Five" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorDigitButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="4" Grid.Row="6" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Six" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorDigitButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="6" Grid.Row="6" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Mul" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorOperatorButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="8" Grid.Row="6" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Fract" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorOperatorButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="0" Grid.Row="8" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="One" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorDigitButtonStyle}" /> |
|||
|
|||
<Button Grid.Column="2" Grid.Row="8" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Two" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorDigitButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="4" Grid.Row="8" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Three" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorDigitButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="6" Grid.Row="8" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Subtract" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorOperatorButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="8" Grid.Row="8" Grid.RowSpan="3" MinWidth="28" MinHeight="55" |
|||
local:Calculator.CalculatorButtonType="Equal" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorOperatorButtonStyle}"/> |
|||
|
|||
<Button Grid.Column="0" Grid.Row="10" Grid.ColumnSpan="3" MinWidth="59" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Zero" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorDigitButtonStyle}" /> |
|||
|
|||
<Button Grid.Column="4" Grid.Row="10" MinWidth="28" MinHeight="26" |
|||
local:Calculator.CalculatorButtonType="Decimal" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorDigitButtonStyle}" /> |
|||
|
|||
<Button Grid.Column="6" Grid.Row="10" MinWidth="28" MinHeight="26" x:Name="Add" |
|||
local:Calculator.CalculatorButtonType="Add" |
|||
Command="local:CalculatorCommands.CalculatorButtonClick" |
|||
Style="{StaticResource CalculatorOperatorButtonStyle}"/> |
|||
</Grid> |
|||
</ControlTemplate> |
|||
|
|||
<Style TargetType="{x:Type local:Calculator}"> |
|||
<Setter Property="Background"> |
|||
<Setter.Value> |
|||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
|||
<GradientStop Color="#FFFAFBFB" Offset="0"/> |
|||
<GradientStop Color="#FFF4F4F4" Offset="1"/> |
|||
</LinearGradientBrush> |
|||
</Setter.Value> |
|||
</Setter> |
|||
<Setter Property="BorderBrush" Value="#FF949494" /> |
|||
<Setter Property="BorderThickness" Value="1" /> |
|||
<Setter Property="FocusVisualStyle" Value="{x:Null}" /> |
|||
<Setter Property="Template"> |
|||
<Setter.Value> |
|||
<ControlTemplate TargetType="{x:Type local:Calculator}"> |
|||
<Border Background="{TemplateBinding Background}" |
|||
BorderBrush="{TemplateBinding BorderBrush}" |
|||
BorderThickness="{TemplateBinding BorderThickness}" |
|||
CornerRadius="3"> |
|||
<Grid Margin="10"> |
|||
<Grid.RowDefinitions> |
|||
<RowDefinition Height="Auto" /> |
|||
<RowDefinition Height="Auto" /> |
|||
</Grid.RowDefinitions> |
|||
<Border Margin="0,0,0,10" Background="White" BorderBrush="#FF949494" BorderThickness="1"> |
|||
<TextBlock FontSize="16" |
|||
HorizontalAlignment="Right" |
|||
Margin="2" |
|||
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}}" /> |
|||
</Border> |
|||
<ContentControl x:Name="PART_CalculatorButtonPanel" Grid.Row="1" Template="{StaticResource CalculatorButtonPanel}" DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}" /> |
|||
</Grid> |
|||
</Border> |
|||
</ControlTemplate> |
|||
</Setter.Value> |
|||
</Setter> |
|||
</Style> |
|||
|
|||
</ResourceDictionary> |
|||
Loading…
Reference in new issue