| 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 | using System.Windows.Input; |
| 9 | using UI.Controls.Base; |
| 10 | |
| 11 | namespace 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 | } |