跳到主要内容

github/tai

公开

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

浏览文件

InputBox.cs

112 行 · 5.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.Controls.Primitives;
9using System.Windows.Media;
10using UI.Controls.Base;
11
12namespace UI.Controls.Input
13{
14 public class InputBox : TextBox
15 {
16 /// <summary>
17 /// 圆角半径
18 /// </summary>
19 public CornerRadius CornerRadius
20 {
21 get { return (CornerRadius)GetValue(CornerRadiusProperty); }
22 set { SetValue(CornerRadiusProperty, value); }
23 }
24 public static readonly DependencyProperty CornerRadiusProperty =
25 DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(InputBox));
26
27 /// <summary>
28 /// 图标
29 /// </summary>
30 public IconTypes Icon
31 {
32 get { return (IconTypes)GetValue(IconProperty); }
33 set { SetValue(IconProperty, value); }
34 }
35 public static readonly DependencyProperty IconProperty =
36 DependencyProperty.Register("Icon", typeof(IconTypes), typeof(InputBox), new PropertyMetadata(IconTypes.None));
37
38 public Thickness BoxPadding { get { return (Thickness)GetValue(BoxPaddingProperty); } set { SetValue(BoxPaddingProperty, value); } }
39 public static readonly DependencyProperty BoxPaddingProperty = DependencyProperty.Register("BoxPadding", typeof(Thickness), typeof(InputBox));
40
41 public string Title { get { return (string)GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } }
42 public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(InputBox));
43
44 public Thickness TitleMargin { get { return (Thickness)GetValue(TitleMarginProperty); } set { SetValue(TitleMarginProperty, value); } }
45 public static readonly DependencyProperty TitleMarginProperty = DependencyProperty.Register("TitleMargin", typeof(Thickness), typeof(InputBox));
46
47 public Thickness IconMargin { get { return (Thickness)GetValue(IconMarginProperty); } set { SetValue(IconMarginProperty, value); } }
48 public static readonly DependencyProperty IconMarginProperty = DependencyProperty.Register("IconMargin", typeof(Thickness), typeof(InputBox));
49
50 public SolidColorBrush IconColor { get { return (SolidColorBrush)GetValue(IconColorProperty); } set { SetValue(IconColorProperty, value); } }
51 public static readonly DependencyProperty IconColorProperty = DependencyProperty.Register("IconColor", typeof(SolidColorBrush), typeof(InputBox));
52
53 public SolidColorBrush TitleColor { get { return (SolidColorBrush)GetValue(TitleColorProperty); } set { SetValue(TitleColorProperty, value); } }
54 public static readonly DependencyProperty TitleColorProperty = DependencyProperty.Register("TitleColor", typeof(SolidColorBrush), typeof(InputBox));
55
56 public double IconSize { get { return (double)GetValue(IconSizeProperty); } set { SetValue(IconSizeProperty, value); } }
57 public static readonly DependencyProperty IconSizeProperty = DependencyProperty.Register("IconSize", typeof(double), typeof(InputBox));
58
59 public double TitleSize { get { return (double)GetValue(TitleSizeProperty); } set { SetValue(TitleSizeProperty, value); } }
60 public static readonly DependencyProperty TitleSizeProperty = DependencyProperty.Register("TitleSize", typeof(double), typeof(InputBox));
61 public string Error { get { return (string)GetValue(ErrorProperty); } set { SetValue(ErrorProperty, value); } }
62 public static readonly DependencyProperty ErrorProperty = DependencyProperty.Register("Error", typeof(string), typeof(InputBox));
63 public bool IsError { get { return (bool)GetValue(IsErrorProperty); } set { SetValue(IsErrorProperty, value); } }
64 public static readonly DependencyProperty IsErrorProperty = DependencyProperty.Register("IsError", typeof(bool), typeof(InputBox));
65
66 public bool IsShowError { get { return (bool)GetValue(IsShowErrorProperty); } set { SetValue(IsShowErrorProperty, value); } }
67 public static readonly DependencyProperty IsShowErrorProperty = DependencyProperty.Register("IsShowError", typeof(bool), typeof(InputBox));
68
69
70 public string Placeholder { get { return (string)GetValue(PlaceholderProperty); } set { SetValue(PlaceholderProperty, value); } }
71 public static readonly DependencyProperty PlaceholderProperty = DependencyProperty.Register("Placeholder", typeof(string), typeof(InputBox));
72 private Popup ErrorPopup;
73
74 public InputBox()
75 {
76 DefaultStyleKey = typeof(InputBox);
77 Unloaded += InputBox_Unloaded;
78 }
79
80 private void InputBox_Unloaded(object sender, RoutedEventArgs e)
81 {
82 Unloaded -= InputBox_Unloaded;
83 if (ErrorPopup != null)
84 {
85 ErrorPopup.Closed -= ErrorPopup_Closed;
86 }
87 }
88
89 public override void OnApplyTemplate()
90 {
91 base.OnApplyTemplate();
92 ErrorPopup = GetTemplateChild("ErrorPopup") as Popup;
93 ErrorPopup.Closed += ErrorPopup_Closed;
94 }
95
96 private void ErrorPopup_Closed(object sender, EventArgs e)
97 {
98 IsShowError = false;
99 }
100
101 public void ShowError()
102 {
103 IsShowError = true;
104 }
105
106 public void HideError()
107 {
108
109 IsShowError = false;
110 }
111 }
112}