跳到主要内容

github/tai

公开

Tai · Windows 软件与网站使用时长统计。上游 Planshit/Tai 的源码镜像,非灵栈原创;MIT 许可。来源:https://github.com/Planshit/Tai 。本次为手动同步,暂不提供安装包。

浏览文件

DatePickerBarItem.cs

69 行 · 2.4 KB历史下载
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using System.Windows;
7using System.Windows.Controls;
8using System.Windows.Input;
9
10namespace 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}