| 1 | |
| 2 | using System; |
| 3 | using System.Collections.Generic; |
| 4 | using System.Text; |
| 5 | using System.Windows; |
| 6 | using System.Windows.Controls; |
| 7 | using System.Windows.Input; |
| 8 | using System.Windows.Media; |
| 9 | using UI.Base.Color; |
| 10 | using UI.Controls.Base; |
| 11 | |
| 12 | namespace UI.Controls.Navigation |
| 13 | { |
| 14 | public class NavigationItem : Control |
| 15 | { |
| 16 | public int ID |
| 17 | { |
| 18 | get { return (int)GetValue(IDProperty); } |
| 19 | set { SetValue(IDProperty, value); } |
| 20 | } |
| 21 | public static readonly DependencyProperty IDProperty = |
| 22 | DependencyProperty.Register("ID", |
| 23 | typeof(int), |
| 24 | typeof(NavigationItem)); |
| 25 | |
| 26 | public ICommand Command |
| 27 | { |
| 28 | get { return (ICommand)GetValue(CommandProperty); } |
| 29 | set { SetValue(CommandProperty, value); } |
| 30 | } |
| 31 | public static readonly DependencyProperty CommandProperty = |
| 32 | DependencyProperty.Register("Command", |
| 33 | typeof(ICommand), |
| 34 | typeof(NavigationItem)); |
| 35 | |
| 36 | public object CommandParameter |
| 37 | { |
| 38 | get { return (object)GetValue(CommandParameterProperty); } |
| 39 | set { SetValue(CommandParameterProperty, value); } |
| 40 | } |
| 41 | public static readonly DependencyProperty CommandParameterProperty = |
| 42 | DependencyProperty.Register("CommandParameter", |
| 43 | typeof(object), |
| 44 | typeof(NavigationItem)); |
| 45 | public IconTypes Icon |
| 46 | { |
| 47 | get { return (IconTypes)GetValue(IconProperty); } |
| 48 | set { SetValue(IconProperty, value); } |
| 49 | } |
| 50 | public static readonly DependencyProperty IconProperty = |
| 51 | DependencyProperty.Register("Icon", |
| 52 | typeof(IconTypes), |
| 53 | typeof(NavigationItem), new PropertyMetadata(IconTypes.None)); |
| 54 | |
| 55 | public IconTypes SelectedIcon |
| 56 | { |
| 57 | get { return (IconTypes)GetValue(SelectedIconIconProperty); } |
| 58 | set { SetValue(SelectedIconIconProperty, value); } |
| 59 | } |
| 60 | public static readonly DependencyProperty SelectedIconIconProperty = |
| 61 | DependencyProperty.Register("SelectedIconIcon", |
| 62 | typeof(IconTypes), |
| 63 | typeof(NavigationItem), new PropertyMetadata(IconTypes.None)); |
| 64 | public ColorTypes IconColor |
| 65 | { |
| 66 | get { return (ColorTypes)GetValue(IconColorProperty); } |
| 67 | set { SetValue(IconColorProperty, value); } |
| 68 | } |
| 69 | public static readonly DependencyProperty IconColorProperty = |
| 70 | DependencyProperty.Register("IconColor", |
| 71 | typeof(ColorTypes), |
| 72 | typeof(NavigationItem), new PropertyMetadata(ColorTypes.Blue)); |
| 73 | public SolidColorBrush IconColorBrush |
| 74 | { |
| 75 | get { return (SolidColorBrush)GetValue(IconColorBrushProperty); } |
| 76 | set { SetValue(IconColorBrushProperty, value); } |
| 77 | } |
| 78 | public static readonly DependencyProperty IconColorBrushProperty = |
| 79 | DependencyProperty.Register("IconColorBrush", |
| 80 | typeof(SolidColorBrush), |
| 81 | typeof(NavigationItem), new PropertyMetadata(UI.Base.Color.Colors.GetColor(ColorTypes.Blue))); |
| 82 | |
| 83 | public string Title |
| 84 | { |
| 85 | get { return (string)GetValue(TitleProperty); } |
| 86 | set { SetValue(TitleProperty, value); } |
| 87 | } |
| 88 | public static readonly DependencyProperty TitleProperty = |
| 89 | DependencyProperty.Register("Title", |
| 90 | typeof(string), |
| 91 | typeof(NavigationItem), new PropertyMetadata(string.Empty)); |
| 92 | |
| 93 | public string BadgeText |
| 94 | { |
| 95 | get { return (string)GetValue(BadgeTextProperty); } |
| 96 | set { SetValue(BadgeTextProperty, value); } |
| 97 | } |
| 98 | public static readonly DependencyProperty BadgeTextProperty = |
| 99 | DependencyProperty.Register("BadgeText", |
| 100 | typeof(string), |
| 101 | typeof(NavigationItem), new PropertyMetadata(string.Empty)); |
| 102 | public string Uri |
| 103 | { |
| 104 | get { return (string)GetValue(UriProperty); } |
| 105 | set { SetValue(UriProperty, value); } |
| 106 | } |
| 107 | public static readonly DependencyProperty UriProperty = |
| 108 | DependencyProperty.Register("Uri", |
| 109 | typeof(string), |
| 110 | typeof(NavigationItem), new PropertyMetadata(string.Empty)); |
| 111 | |
| 112 | public bool IsSelected |
| 113 | { |
| 114 | get { return (bool)GetValue(IsSelectedProperty); } |
| 115 | set { SetValue(IsSelectedProperty, value); } |
| 116 | } |
| 117 | public static readonly DependencyProperty IsSelectedProperty = |
| 118 | DependencyProperty.Register("IsSelected", |
| 119 | typeof(bool), |
| 120 | typeof(NavigationItem), new PropertyMetadata(false)); |
| 121 | |
| 122 | public delegate void NavigationEventHandler(object sender, MouseButtonEventArgs e); |
| 123 | public event NavigationEventHandler MouseUp; |
| 124 | public NavigationItem() |
| 125 | { |
| 126 | DefaultStyleKey = typeof(NavigationItem); |
| 127 | } |
| 128 | protected override void OnMouseUp(MouseButtonEventArgs e) |
| 129 | { |
| 130 | base.OnMouseUp(e); |
| 131 | MouseUp?.Invoke(this, e); |
| 132 | if (e.ChangedButton == MouseButton.Left) |
| 133 | { |
| 134 | Command?.Execute(CommandParameter); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | protected override void OnMouseEnter(MouseEventArgs e) |
| 139 | { |
| 140 | base.OnMouseEnter(e); |
| 141 | VisualStateManager.GoToState(this, "MouseOver", true); |
| 142 | } |
| 143 | protected override void OnMouseLeave(MouseEventArgs e) |
| 144 | { |
| 145 | base.OnMouseLeave(e); |
| 146 | VisualStateManager.GoToState(this, "Normal", true); |
| 147 | } |
| 148 | } |
| 149 | } |