跳到主要内容

github/tai

公开

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

浏览文件

ChartItemTypeColumn.cs

157 行 · 4.3 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;
9using System.Windows.Shapes;
10using UI.Base.Color;
11
12namespace UI.Controls.Charts
13{
14 public class ChartItemTypeColumn : Control
15 {
16 #region MaxValue 最大值
17 /// <summary>
18 /// 样式类型
19 /// </summary>
20 public double MaxValue
21 {
22 get { return (double)GetValue(MaxValueProperty); }
23 set { SetValue(MaxValueProperty, value); }
24 }
25 public static readonly DependencyProperty MaxValueProperty =
26 DependencyProperty.Register("MaxValue",
27 typeof(double),
28 typeof(ChartItemTypeColumn));
29
30
31 #endregion
32
33 #region 值
34 /// <summary>
35 /// 样式类型
36 /// </summary>
37 public double Value
38 {
39 get { return (double)GetValue(ValueProperty); }
40 set { SetValue(ValueProperty, value); }
41 }
42 public static readonly DependencyProperty ValueProperty =
43 DependencyProperty.Register("Value",
44 typeof(double),
45 typeof(ChartItemTypeColumn));
46
47
48 #endregion
49 #region 颜色
50 /// <summary>
51 /// 样式类型
52 /// </summary>
53 public string Color
54 {
55 get { return (string)GetValue(ColorProperty); }
56 set { SetValue(ColorProperty, value); }
57 }
58 public static readonly DependencyProperty ColorProperty =
59 DependencyProperty.Register("Color",
60 typeof(string),
61 typeof(ChartItemTypeColumn));
62
63
64 #endregion
65 #region 列名
66 /// <summary>
67 /// 样式类型
68 /// </summary>
69 public string ColumnName
70 {
71 get { return (string)GetValue(ColumnNameProperty); }
72 set { SetValue(ColumnNameProperty, value); }
73 }
74 public static readonly DependencyProperty ColumnNameProperty =
75 DependencyProperty.Register("ColumnName",
76 typeof(string),
77 typeof(ChartItemTypeColumn));
78
79
80 #endregion
81
82 private bool isRendering = false;
83 private Rectangle ValueBlockObj;
84 private Border ValueContainer;
85 private bool IsAddEvent = false;
86 public ChartItemTypeColumn()
87 {
88 DefaultStyleKey = typeof(ChartItemTypeColumn);
89 Unloaded += ChartItemTypeColumn_Unloaded;
90 }
91
92 public override void OnApplyTemplate()
93 {
94 base.OnApplyTemplate();
95 ValueBlockObj = GetTemplateChild("ValueBlockObj") as Rectangle;
96 ValueContainer = GetTemplateChild("ValueContainer") as Border;
97 if (!IsAddEvent)
98 {
99 Loaded += ChartItemTypeColumn_Loaded;
100 }
101 }
102
103 private void ChartItemTypeColumn_Unloaded(object sender, RoutedEventArgs e)
104 {
105 Loaded -= ChartItemTypeColumn_Loaded;
106 Unloaded -= ChartItemTypeColumn_Unloaded;
107 }
108
109 private void ChartItemTypeColumn_Loaded(object sender, RoutedEventArgs e)
110 {
111 Render();
112 IsAddEvent = true;
113 }
114
115
116 private void Render()
117 {
118 if (isRendering)
119 {
120 return;
121 }
122
123 if (!string.IsNullOrEmpty(Color))
124 {
125 ValueBlockObj.Fill = Colors.GetFromString(Color);
126 }
127 //isRendering = true;
128
129 Update();
130 //this.SizeChanged += (e, c) =>
131 //{
132 // if (MaxValue <= 0)
133 // {
134 // return;
135 // }
136 // Update();
137 //};
138 }
139
140 public void Update()
141 {
142
143 ValueBlockObj.Height = (Value / MaxValue) * (ValueContainer.ActualHeight);
144 }
145
146 protected override void OnMouseEnter(MouseEventArgs e)
147 {
148 base.OnMouseEnter(e);
149 VisualStateManager.GoToState(this, "MouseOver", true);
150 }
151 protected override void OnMouseLeave(MouseEventArgs e)
152 {
153 base.OnMouseLeave(e);
154 VisualStateManager.GoToState(this, "NormalState", true);
155 }
156 }
157}