| 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | using System.Linq; |
| 4 | using System.Text; |
| 5 | using System.Threading.Tasks; |
| 6 | using System.Windows; |
| 7 | using System.Windows.Controls; |
| 8 | using System.Windows.Input; |
| 9 | using UI.Controls.Base; |
| 10 | |
| 11 | namespace UI.Controls.Button |
| 12 | { |
| 13 | public class IconButton : ContentControl |
| 14 | { |
| 15 | public ICommand Command |
| 16 | { |
| 17 | get { return (ICommand)GetValue(CommandProperty); } |
| 18 | set { SetValue(CommandProperty, value); } |
| 19 | } |
| 20 | public static readonly DependencyProperty CommandProperty = |
| 21 | DependencyProperty.Register("Command", |
| 22 | typeof(ICommand), |
| 23 | typeof(IconButton)); |
| 24 | |
| 25 | public object CommandParameter |
| 26 | { |
| 27 | get { return (object)GetValue(CommandParameterProperty); } |
| 28 | set { SetValue(CommandParameterProperty, value); } |
| 29 | } |
| 30 | public static readonly DependencyProperty CommandParameterProperty = |
| 31 | DependencyProperty.Register("CommandParameter", |
| 32 | typeof(object), |
| 33 | typeof(IconButton)); |
| 34 | public IconTypes Icon |
| 35 | { |
| 36 | get { return (IconTypes)GetValue(IconProperty); } |
| 37 | set { SetValue(IconProperty, value); } |
| 38 | } |
| 39 | public static readonly DependencyProperty IconProperty = |
| 40 | DependencyProperty.Register("Icon", |
| 41 | typeof(IconTypes), |
| 42 | typeof(IconButton), new PropertyMetadata(IconTypes.None)); |
| 43 | public IconButton() |
| 44 | { |
| 45 | DefaultStyleKey = typeof(IconButton); |
| 46 | } |
| 47 | |
| 48 | protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) |
| 49 | { |
| 50 | base.OnMouseLeftButtonUp(e); |
| 51 | VisualStateManager.GoToState(this, "MouseOver", true); |
| 52 | |
| 53 | Command?.Execute(CommandParameter); |
| 54 | } |
| 55 | protected override void OnMouseEnter(MouseEventArgs e) |
| 56 | { |
| 57 | base.OnMouseEnter(e); |
| 58 | VisualStateManager.GoToState(this, "MouseOver", true); |
| 59 | } |
| 60 | protected override void OnMouseLeave(MouseEventArgs e) |
| 61 | { |
| 62 | base.OnMouseLeave(e); |
| 63 | VisualStateManager.GoToState(this, "Normal", true); |
| 64 | } |
| 65 | protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) |
| 66 | { |
| 67 | base.OnMouseLeftButtonDown(e); |
| 68 | VisualStateManager.GoToState(this, "Pressed", true); |
| 69 | } |
| 70 | } |
| 71 | } |