跳到主要内容

github/tai

公开

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

浏览文件

Button.cs

75 行 · 2.2 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 UI.Controls.Base;
10
11namespace UI.Controls.Button
12{
13 public class Button : System.Windows.Controls.Button
14 {
15 public IconTypes Icon
16 {
17 get { return (IconTypes)GetValue(IconProperty); }
18 set { SetValue(IconProperty, value); }
19 }
20 public static readonly DependencyProperty IconProperty =
21 DependencyProperty.Register("Icon",
22 typeof(IconTypes),
23 typeof(Button), new PropertyMetadata(IconTypes.None));
24
25 public string Text
26 {
27 get { return (string)GetValue(TextProperty); }
28 set { SetValue(TextProperty, value); }
29 }
30 public static readonly DependencyProperty TextProperty =
31 DependencyProperty.Register("Text",
32 typeof(string),
33 typeof(Button));
34 public bool Value
35 {
36 get { return (bool)GetValue(ValueProperty); }
37 set { SetValue(ValueProperty, value); }
38 }
39 public static readonly DependencyProperty ValueProperty =
40 DependencyProperty.Register("Value",
41 typeof(bool),
42 typeof(Button), new PropertyMetadata(new PropertyChangedCallback(OnPropertyChanged)));
43
44 private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
45 {
46 Button button = (Button)d;
47
48 button.SetContent();
49
50 }
51
52 public Button()
53 {
54 DefaultStyleKey = typeof(Button);
55 }
56
57 public override void OnApplyTemplate()
58 {
59 base.OnApplyTemplate();
60 SetContent();
61 }
62
63 private void SetContent()
64 {
65 if (string.IsNullOrEmpty(Text) || Text.IndexOf('?') == -1 || Text.IndexOf(':') == -1)
66 {
67 return;
68 }
69
70 string yes = Text.Substring(Text.IndexOf('?') + 1, Text.IndexOf(':') - 1);
71 string no = Text.Substring(Text.IndexOf(':') + 1);
72 Content = Value ? yes : no;
73 }
74 }
75}