跳到主要内容

github/tai

公开

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

浏览文件

Text.cs

64 行 · 1.8 KB历史下载
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using System.Windows;
7using System.Windows.Controls;
8
9namespace UI.Controls.Base
10{
11 public class Text : Control
12 {
13 public string Content
14 {
15 get { return (string)GetValue(ContentProperty); }
16 set { SetValue(ContentProperty, value); }
17 }
18 public static readonly DependencyProperty ContentProperty =
19 DependencyProperty.Register("Content",
20 typeof(string),
21 typeof(Text));
22 public bool Value
23 {
24 get { return (bool)GetValue(ValueProperty); }
25 set { SetValue(ValueProperty, value); }
26 }
27 public static readonly DependencyProperty ValueProperty =
28 DependencyProperty.Register("Value",
29 typeof(bool),
30 typeof(Text), new PropertyMetadata(new PropertyChangedCallback(OnPropertyChanged)));
31
32 private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
33 {
34 Text c = (Text)d;
35
36 c.SetContent();
37
38 }
39
40 public string Content_ { get; set; }
41 public Text()
42 {
43 DefaultStyleKey = typeof(Text);
44 }
45
46 public override void OnApplyTemplate()
47 {
48 base.OnApplyTemplate();
49 SetContent();
50 }
51
52 private void SetContent()
53 {
54 if (string.IsNullOrEmpty(Content) || Content.IndexOf('?') == -1 || Content.IndexOf(':') == -1)
55 {
56 return;
57 }
58
59 string yes = Content.Substring(Content.IndexOf('?') + 1, Content.IndexOf(':') - 1);
60 string no = Content.Substring(Content.IndexOf(':') + 1);
61 Content_ = Value ? yes : no;
62 }
63 }
64}