跳到主要内容

github/tai

公开

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

浏览文件

ChartsItemTypeMonth.cs

176 行 · 5.5 KB历史下载
1using Core.Librarys.Image;
2using System;
3using System.Collections.Generic;
4using System.Diagnostics;
5using System.Linq;
6using System.Text;
7using System.Threading.Tasks;
8using System.Windows;
9using System.Windows.Controls;
10using System.Windows.Data;
11using System.Windows.Documents;
12using System.Windows.Input;
13using System.Windows.Media;
14using System.Windows.Media.Imaging;
15using System.Windows.Navigation;
16using System.Windows.Shapes;
17using UI.Controls.Charts.Model;
18
19namespace UI.Controls.Charts
20{
21 public class ChartsItemTypeMonth : Control
22 {
23 #region Data 数据
24 /// <summary>
25 /// 数据
26 /// </summary>
27 public ChartsDataModel Data
28 {
29 get { return (ChartsDataModel)GetValue(DataProperty); }
30 set { SetValue(DataProperty, value); }
31 }
32 public static readonly DependencyProperty DataProperty =
33 DependencyProperty.Register("Data",
34 typeof(ChartsDataModel),
35 typeof(ChartsItemTypeMonth));
36
37
38 #endregion
39
40 #region MaxValue 最大值
41 /// <summary>
42 /// 样式类型
43 /// </summary>
44 public double MaxValue
45 {
46 get { return (double)GetValue(MaxValueProperty); }
47 set { SetValue(MaxValueProperty, value); }
48 }
49 public static readonly DependencyProperty MaxValueProperty =
50 DependencyProperty.Register("MaxValue",
51 typeof(double),
52 typeof(ChartsItemTypeMonth));
53
54
55 #endregion
56
57 #region IsLoading 是否正在加载中
58 /// <summary>
59 /// 是否正在加载中
60 /// </summary>
61 public bool IsLoading
62 {
63 get { return (bool)GetValue(IsLoadingProperty); }
64 set { SetValue(IsLoadingProperty, value); }
65 }
66 public static readonly DependencyProperty IsLoadingProperty =
67 DependencyProperty.Register("IsLoading",
68 typeof(bool),
69 typeof(ChartsItemTypeMonth));
70
71
72 #endregion
73 #region IsSelected 是否选中
74 /// <summary>
75 /// 是否选中
76 /// </summary>
77 public bool IsSelected
78 {
79 get { return (bool)GetValue(IsSelectedProperty); }
80 set { SetValue(IsSelectedProperty, value); }
81 }
82 public static readonly DependencyProperty IsSelectedProperty =
83 DependencyProperty.Register("IsSelected",
84 typeof(bool),
85 typeof(ChartsItemTypeMonth));
86
87
88 #endregion
89 //private TextBlock NameTextObj, ValueTextObj;
90 private Rectangle ValueBlockObj;
91 //private StackPanel ValueContainer;
92 //private Image IconObj;
93 private bool isRendering = false;
94 private bool IsAddEvent = false;
95
96 public ChartsItemTypeMonth()
97 {
98 DefaultStyleKey = typeof(ChartsItemTypeMonth);
99
100 Unloaded += ChartsItemTypeMonth_Unloaded;
101 }
102
103 private void ChartsItemTypeMonth_Unloaded(object sender, RoutedEventArgs e)
104 {
105 Unloaded -= ChartsItemTypeMonth_Unloaded;
106 Loaded -= ChartsItemTypeMonth_Loaded;
107 }
108
109 public override void OnApplyTemplate()
110 {
111 base.OnApplyTemplate();
112 //NameTextObj = GetTemplateChild("NameTextObj") as TextBlock;
113 //ValueTextObj = GetTemplateChild("ValueTextObj") as TextBlock;
114 ValueBlockObj = GetTemplateChild("ValueBlockObj") as Rectangle;
115 //ValueContainer = GetTemplateChild("ValueContainer") as StackPanel;
116
117 //IconObj = GetTemplateChild("IconObj") as Image;
118 if (!IsAddEvent)
119 {
120 IsAddEvent = true;
121 Loaded += ChartsItemTypeMonth_Loaded;
122 }
123 }
124
125 private void ChartsItemTypeMonth_Loaded(object sender, RoutedEventArgs e)
126 {
127 Render();
128 }
129
130 private void Render()
131 {
132 if (isRendering || Data == null)
133 {
134 return;
135 }
136 isRendering = true;
137 //Loaded += (s, e) =>
138 //{
139 // ValueBlockObj.Width = ValueBlockObj.Height = (Data.Value / MaxValue) * ActualWidth;
140 //};
141
142 double size = (Data.Value / MaxValue) * ActualWidth;
143 if (size > 0 && size < 8) //防止历史数值太小界面无显示效果
144 size = 8;
145 ValueBlockObj.Width = ValueBlockObj.Height = size;
146 ToolTip = Data.DateTime.ToString("yyyy年MM月dd日") + " " + (string.IsNullOrEmpty(Data.Tag) ? "无数据" : Data.Tag);
147
148 if (Data.DateTime.Date == DateTime.Now.Date)
149 {
150 IsSelected = true;
151 ToolTip = "[今日] " + ToolTip;
152 }
153 //ValueTextObj.Text = Data.DateTime.Day.ToString();
154 //NameTextObj.Text = Data.Name;
155 //NameTextObj.SizeChanged += (e, c) =>
156 //{
157 // // 处理文字过长显示
158 // if (NameTextObj.ActualWidth > 121 && NameTextObj.FontSize > 8)
159 // {
160 // NameTextObj.FontSize = NameTextObj.FontSize - 1;
161 // }
162 //};
163 //ValueTextObj.Text = Data.Tag;
164 //IconObj.Source = Imager.Load(Data.Icon);
165
166 //ValueTextObj.SizeChanged += (e, c) =>
167 //{
168 // //if (MaxValue <= 0)
169 // //{
170 // // return;
171 // //}
172 // ValueBlockObj.Width = ValueBlockObj.Height = (Data.Value / MaxValue) * ActualWidth;
173 //};
174 }
175 }
176}