ChartButton.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace ivf_tl_Operate.CustomUserControls
  16. {
  17. /// <summary>
  18. /// ChartButton.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class ChartButton : UserControl
  21. {
  22. public ChartButton()
  23. {
  24. InitializeComponent();
  25. }
  26. /// <summary>
  27. /// 按钮内容
  28. /// </summary>
  29. public new string Content
  30. {
  31. get { return (string)GetValue(ContentProperty); }
  32. set { SetValue(ContentProperty, value); }
  33. }
  34. public static new readonly DependencyProperty ContentProperty =
  35. DependencyProperty.Register("Content", typeof(string), typeof(ChartButton), new PropertyMetadata("0", new PropertyChangedCallback(OnContentPropertyChangedCallback)));
  36. private static void OnContentPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  37. {
  38. if (!(d is ChartButton source)) return;
  39. if (!(e.NewValue is string content)) return;
  40. source._content.Text = content;
  41. }
  42. /// <summary>
  43. /// 是否选中
  44. /// </summary>
  45. public bool IsSelected
  46. {
  47. get { return (bool)GetValue(IsSelectedProperty); }
  48. set { SetValue(IsSelectedProperty, value); }
  49. }
  50. public static readonly DependencyProperty IsSelectedProperty =
  51. DependencyProperty.Register("IsSelected", typeof(bool), typeof(ChartButton), new PropertyMetadata(false, new PropertyChangedCallback(OnIsSelectedPropertyChangedCallback)));
  52. private static void OnIsSelectedPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  53. {
  54. if (!(d is ChartButton source)) return;
  55. if (!(e.NewValue is bool selected)) return;
  56. if (selected)
  57. {
  58. source._img.Visibility = Visibility.Visible;
  59. source._content.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));//白色
  60. }
  61. else
  62. {
  63. source._img.Visibility = Visibility.Hidden;
  64. source._content.Foreground = new SolidColorBrush(Color.FromRgb(110, 114, 118));//灰色
  65. }
  66. }
  67. public Brush TextForeground
  68. {
  69. get { return (Brush)GetValue(TextForegroundProperty); }
  70. set { SetValue(TextForegroundProperty, value); }
  71. }
  72. public static readonly DependencyProperty TextForegroundProperty =
  73. DependencyProperty.Register("TextForeground", typeof(Brush), typeof(ChartButton), new PropertyMetadata(new SolidColorBrush(Color.FromRgb(110, 114, 118)), new PropertyChangedCallback(OnForegroundPropertyChangedCallback)));
  74. private static void OnForegroundPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  75. {
  76. if (!(d is ChartButton source)) return;
  77. if (!(e.NewValue is Brush newBrush)) return;
  78. source._content.Foreground = newBrush;
  79. }
  80. }
  81. }