PhotoButton.xaml.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using ivf_tl_Entity;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace ivf_tl_Operate.CustomUserControls
  17. {
  18. /// <summary>
  19. /// PhotoButton.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class PhotoButton : UserControl
  22. {
  23. public PhotoButton()
  24. {
  25. InitializeComponent();
  26. }
  27. /// <summary>
  28. /// 筛选设置实体
  29. /// </summary>
  30. public PhotoBoxSetting PhotoBoxSetting { get; set; }
  31. public new double Width
  32. {
  33. get { return (double)GetValue(WidthProperty); }
  34. set { SetValue(WidthProperty, value); }
  35. }
  36. public static new readonly DependencyProperty WidthProperty =
  37. DependencyProperty.Register("Width", typeof(double), typeof(PhotoButton), new PropertyMetadata(140.0, new PropertyChangedCallback(OnWidthPropertyChangedCallback)));
  38. private static void OnWidthPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  39. {
  40. if (!(d is PhotoButton source)) return;
  41. if (!(e.NewValue is double width)) return;
  42. source._border.Width = width;
  43. }
  44. public new double Height
  45. {
  46. get { return (double)GetValue(HeightProperty); }
  47. set { SetValue(HeightProperty, value); }
  48. }
  49. public static new readonly DependencyProperty HeightProperty =
  50. DependencyProperty.Register("Height", typeof(double), typeof(PhotoButton), new PropertyMetadata(80.0, new PropertyChangedCallback(OnHeightPropertyChangedCallback)));
  51. private static void OnHeightPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  52. {
  53. if (!(d is PhotoButton source)) return;
  54. if (!(e.NewValue is double height)) return;
  55. source._border.Height = height;
  56. }
  57. /// <summary>
  58. /// 按钮内容
  59. /// </summary>
  60. public new string Content
  61. {
  62. get { return (string)GetValue(ContentProperty); }
  63. set { SetValue(ContentProperty, value); }
  64. }
  65. public static new readonly DependencyProperty ContentProperty =
  66. DependencyProperty.Register("Content", typeof(string), typeof(PhotoButton), new PropertyMetadata("", new PropertyChangedCallback(OnContentPropertyChangedCallback)));
  67. private static void OnContentPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  68. {
  69. if (!(d is PhotoButton source)) return;
  70. if (!(e.NewValue is string content)) return;
  71. source._text.Text = content;
  72. }
  73. /// <summary>
  74. /// 字号
  75. /// </summary>
  76. public new double FontSize
  77. {
  78. get { return (double)GetValue(FontSizeProperty); }
  79. set { SetValue(FontSizeProperty, value); }
  80. }
  81. public static new readonly DependencyProperty FontSizeProperty =
  82. DependencyProperty.Register("FontSize", typeof(double), typeof(PhotoButton), new PropertyMetadata(33.0, new PropertyChangedCallback(OnFontSizePropertyChangedCallback)));
  83. private static void OnFontSizePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  84. {
  85. if (!(d is PhotoButton source)) return;
  86. if (!(e.NewValue is double fontsize)) return;
  87. source._text.FontSize = fontsize;
  88. }
  89. /// <summary>
  90. /// 是否选中
  91. /// </summary>
  92. public bool IsSelected
  93. {
  94. get { return (bool)GetValue(IsSelectedProperty); }
  95. set { SetValue(IsSelectedProperty, value); }
  96. }
  97. public static readonly DependencyProperty IsSelectedProperty =
  98. DependencyProperty.Register("IsSelected", typeof(bool), typeof(PhotoButton), new PropertyMetadata(false, new PropertyChangedCallback(OnIsSelectedPropertyChangedCallback)));
  99. private static void OnIsSelectedPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  100. {
  101. if (!(d is PhotoButton source)) return;
  102. if (!(e.NewValue is bool isSelected)) return;
  103. if (isSelected)
  104. {
  105. LinearGradientBrush brush = new LinearGradientBrush();
  106. brush.StartPoint = new Point(0, 0);
  107. brush.EndPoint = new Point(0, 1);
  108. brush.GradientStops.Add(new GradientStop(Color.FromRgb(61, 98, 148), 0.1));//蓝色
  109. brush.GradientStops.Add(new GradientStop(Color.FromRgb(117, 153, 204), 0.9));
  110. source._border.Background = brush;
  111. }
  112. else
  113. {
  114. LinearGradientBrush brush = new LinearGradientBrush();
  115. brush.StartPoint = new Point(0, 0);
  116. brush.EndPoint = new Point(0, 1);
  117. brush.GradientStops.Add(new GradientStop(Color.FromRgb(111, 115, 119), 0.1));//灰色
  118. brush.GradientStops.Add(new GradientStop(Color.FromRgb(173, 177, 182), 0.9));
  119. source._border.Background = brush;
  120. }
  121. }
  122. }
  123. }