| 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | using System.Linq; |
| 4 | using System.Text; |
| 5 | using System.Threading.Tasks; |
| 6 | using System.Windows; |
| 7 | using System.Windows.Controls; |
| 8 | |
| 9 | namespace 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 | } |