| 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 | |
| 10 | namespace UI.Controls.DatePickerBar |
| 11 | { |
| 12 | public class DatePickerBarItem : Control |
| 13 | { |
| 14 | public string Title |
| 15 | { |
| 16 | get { return (string)GetValue(TitleProperty); } |
| 17 | set { SetValue(TitleProperty, value); } |
| 18 | } |
| 19 | public static readonly DependencyProperty TitleProperty = |
| 20 | DependencyProperty.Register("Title", typeof(string), typeof(DatePickerBarItem)); |
| 21 | |
| 22 | |
| 23 | public bool IsSelected |
| 24 | { |
| 25 | get { return (bool)GetValue(IsSelectedProperty); } |
| 26 | set { SetValue(IsSelectedProperty, value); } |
| 27 | } |
| 28 | public static readonly DependencyProperty IsSelectedProperty = |
| 29 | DependencyProperty.Register("IsSelected", typeof(bool), typeof(DatePickerBarItem)); |
| 30 | public bool IsDisabled |
| 31 | { |
| 32 | get { return (bool)GetValue(IsDisabledProperty); } |
| 33 | set { SetValue(IsDisabledProperty, value); } |
| 34 | } |
| 35 | public static readonly DependencyProperty IsDisabledProperty = |
| 36 | DependencyProperty.Register("IsDisabled", typeof(bool), typeof(DatePickerBarItem)); |
| 37 | public DateTime Date |
| 38 | { |
| 39 | get { return (DateTime)GetValue(DateProperty); } |
| 40 | set { SetValue(DateProperty, value); } |
| 41 | } |
| 42 | public static readonly DependencyProperty DateProperty = |
| 43 | DependencyProperty.Register("Date", typeof(DateTime), typeof(DatePickerBarItem), new PropertyMetadata(new PropertyChangedCallback(OnPropertyChanged))); |
| 44 | |
| 45 | private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 46 | { |
| 47 | var control = d as DatePickerBarItem; |
| 48 | if (e.NewValue != e.OldValue) |
| 49 | { |
| 50 | control.IsDisabled = control.Date > DateTime.Now.Date; |
| 51 | } |
| 52 | } |
| 53 | public DatePickerBarItem() |
| 54 | { |
| 55 | DefaultStyleKey = typeof(DatePickerBarItem); |
| 56 | |
| 57 | } |
| 58 | protected override void OnMouseEnter(MouseEventArgs e) |
| 59 | { |
| 60 | base.OnMouseEnter(e); |
| 61 | VisualStateManager.GoToState(this, "MouseOver", true); |
| 62 | } |
| 63 | protected override void OnMouseLeave(MouseEventArgs e) |
| 64 | { |
| 65 | base.OnMouseLeave(e); |
| 66 | VisualStateManager.GoToState(this, "Normal", true); |
| 67 | } |
| 68 | } |
| 69 | } |